WASHINGTON - US President Barack Obama made his first visit to an American mosque on Wednesday, with a message focused on religious tolerance and unity and calling for all Americans to work together to stamp out anti-Muslim prejudice.

“An attack on one faith is an attack on all our faiths,” Obama said, adding, “We have to be consistent in condemning hateful rhetoric none of us can by bystanders to bigotry.”

The president condemned what he called “inexcusable political rhetoric against Muslim Americans that has no place in our country.”

Speaking to Muslim Americans at the Islamic Society of Baltimore, Obama called for unity among American faith communities, recognised the contributions of Muslim citizens, and asked for Muslims around the world to help combat the extremist ideologies of groups like the Islamic State.

“The first thing I want to say is two words that Muslim Americans don’t hear often enough,” Obama said. “Thank you.”

He decried the surge of threats and intimidation of American Muslim communities following the terrorist attack in San Bernardino, California, last year.

“We’ve seen children bullied, we’ve seen mosques vandalized,” he said. “It’s not who we are. We’re one American family. And when any part of our family begins to feel separate or second class, it tears at the heart of our nation.”

Obama had earlier started his tour of the Islamic Society of Baltimore, one of the largest mosques in the mid-Atlantic region, with a roundtable with Muslim community leaders. He then segued into a talk before a packed auditorium to denounce the rise in “extremist elements” who twist Islamic text into violent ideology — and, in turn, the innocent Muslims who are attacked because of that “radical tiny minority.”

The Islamic Society of Baltimore received threats twice last year, Obama said.

“We’re one American family, and when any part of our family starts to feel second class or separate or targeted, it tears at the very fabric of our nation,” the president said.

Muslims, he added, are “some of the most resilient and patriotic Americans you’ll ever meet.”

His meeting comes at a tense time for Muslim Americans in the wake of terror attacks by religious extremists in the US and abroad, and as anti-Islam rhetoric flares on the presidential campaign trail.

For Muslim advocates, Obama’s visit was a long-awaited gesture to a community that has warned of escalating vitriol against them that has accompanied the public’s concern about the Islamic State and other extremist groups. Although Obama has visited mosques overseas in the past, he waited until his final year in office to make such a visit at home, reflecting the sensitivity of the issue.

One of the participants meeting with Obama, Ibtihaj Muhammad, a Muslim woman, has qualified for a spot on the United States Olympic Team for the Rio de Janeiro 2016 Olympic Games. The White House said she’ll make history as the first United States Olympian to compete in a hijab.

A study by a California State University, San Bernardino, professor found hate crimes targeting Muslim businesses and mosques tripled in 2015. The number of incidents grew after the deadly siege in Paris in November and then again after the December massacre of 14 people in San Bernardino by husband and wife shooters who had apparently pledged allegiance to ISIS online.

On Tuesday, White House spokesman Josh Earnest also condemned the heated rhetoric used by “some Republicans to try to marginalize law-abiding, patriotic Muslim Americans.”

“It’s just offensive to a lot of Americans who recognize that those kinds of cynical political tactics run directly contrary to the values that we hold dear in this country,” Earnest told reporters. “And I think the president is looking forward to the opportunity to make that point.”

Earnest didn’t specifically mention Republican candidate Donald Trump, who said in November he “would certainly implement” a database to track Muslims in America and then suggested in December a full ban on Muslims entering the country as a way to prevent extremist activity.

During his State of the Union address in January, Obama struck back at the message of intolerance that seems to have animated some of the presidential race.

“Muslim Americans are our friends and our neighbors; our co-workers, our sports heroes — and, yes, they are our men and women in uniform,” Obama said.

While the president has visited mosques during his official trips to the Middle East and Southeast Asia, he had not accepted previous invites made by Muslims here. Muslims make up about 1 percent of the US population.

In December, the White House held a meeting with prominent Muslim and Sikh Americans over tensions in their communities, and leaders then suggested that Obama to visit a mosque to speak out against Islamophobia.

President George W Bush had visited the Islamic Cultural Center of Washington, DC, following the 9/11 attacks.

The Islamic Society of Baltimore has about 3,000 congregants, according to The Baltimore Sun, and runs a K-12 school, summer camp and health clinic.