WATCH: Obama blasts 'inexcusable' anti-Muslim political rhetoric
President Barack Obama delivers the State of The Union address on January 20, 2015, at the US Capitol in Washington, DC (AFP Photo/Mandel Ngan)

Barack Obama on Wednesday offered an impassioned rebuttal of "inexcusable" Republican election-year rhetoric against Muslims as he made his first trip to an American mosque, seven years into his presidency.

Obama, whose grandfather converted to Islam, made the short trip to the Islamic Society of Baltimore mosque, where he met community leaders and called on Americans not to be "bystanders to bigotry."

Invoking the Prophet Mohammed and hailing the tolerance shown by American political icons from Thomas Jefferson to Dwight Eisenhower, Obama hit out at anti-Islamic sentiment that is "not who we are."

"We've heard inexcusable political rhetoric against Muslim-Americans that has no place in our country," he said, lauding Muslim-Americans who were sports heroes, entrepreneurs and the architect behind the skyscrapers of Chicago.

His comments comes as a shrill election debate has sullied America's image abroad, and jihadist attacks in San Bernardino and Philadelphia threatened to shatter post-9/11 religious solidarity at home.

Six days after the 2001 attacks in New York and Washington, then Republican president George W. Bush visited the Islamic Center of Washington, declaring "Islam is peace."

Today, Republican presidential candidate Donald Trump has wooed conservative voters by demanding a ban on Muslim immigrants, while frontrunner Ted Cruz has advocated Christian-only admissions and championed "Judeo-Christian values."

On Wednesday, Obama said: "An attack on one faith is an attack on all our faiths."

He also criticized the media and Hollywood, which he said portray Muslims in a narrow way.

"Our television shows should have Muslim characters that are unrelated to national security," he said.

- 'Thank you' -

Obama had visited mosques in Malaysia, Indonesia and Egypt as president, but this was his first visit to one of America's 2,000-plus places of Islamic worship.

In 2009, a freshly elected Obama traveled to Cairo to call for a "new beginning" with the Muslim world.

Much of Obama's foreign policy agenda has focused on improving ties with Muslim nations, from making a nuclear deal with Iran to ending wars in Iraq and Afghanistan.

But the effort has been stymied by continued confrontation with jihadist groups and military strikes in Afghanistan, Iraq, Libya, Pakistan, Somalia, Syria and Yemen.

Obama restated his case that organizations like the Islamic State group pervert Islam and do not represent the vast majority of Muslims.

The president offered "two words that Muslim-Americans don't hear often enough, and that is thank you," saying they help unite the country in "one American family."

But he also called on Muslims to help tackle radicalization.

"How do we defend ourselves against organizations that are bent on killing innocents?" he asked.

"It can't be the work of any one faith alone. It can't be just a burden on the Muslim community, although the Muslim community has to play a role."

That message is a vexed one for members of the community, including those who oppose violence.

"I know national security will come up in the speech just because of the climate of today," said Riham Osman of the Muslim Public Affairs Council, an advocacy group, ahead of the speech.

"It does upset me a little bit that it is his first time coming to visit a mosque, and there will be kids there who have grown up in this post 9/11 era and their faith is constantly linked to national security and extremism."

The United States is home to around 3.3 million Muslims.

Around 81 Muslim-Americans were involved in violent extremist plots in 2015, according to the Triangle Center on Terrorism and Homeland Security.

Watch video, uploaded to YouTube by CNN, below: