President Obama (right) and first lady Michelle Obama are led on a tour by Grand Imam Ali Mustafa Yaqub at the Istiqlal Mosque in Jakarta, Indonesia, on Nov. 10, 2010. (Associated Press) **FILE** more >

The White House said Monday that President Obama’s visit to a Baltimore mosque this week is “important for the country” in light of anti-Muslim sentiment from Republican presidential candidates.

Mr. Obama’s visit to the Islamic Society of Baltimore on Wednesday will be “an opportunity to reaffirm that religious freedom and religious tolerance [are] essential to our way of life in this country,” said White House press secretary Josh Earnest.

“The president’s visit I think, is an important moment to acknowledge those two things,” Mr. Earnest said. “No one, whether they’re a political candidate or not, should feel like it is acceptable to somehow put those religious freedoms at risk.”

Mr. Obama has criticized some of the Republican presidential candidates, notably Donald Trump and Sen. Ted Cruz of Texas, for proposing a temporary ban on Muslims emigrating to the U.S. or a religious test for refugees entering the country. Many in the GOP, and some congressional Democrats, are opposed to Mr. Obama’s program to allow up to 10,000 Syrian refugees into the U.S. this year.

The refugee program has raised fears that Islamist extremists could slip through the screening process, a concern that was heightened after Islamic State-inspired terrorist attacks in Paris and in San Bernardino, California, late last year.

The president’s spokesman said Mr. Trump “is not the only Republican presidential candidate to suggest that a religious test should be imposed on individuals entering the United States.”

“It has, unfortunately, infected our political debate in a way that doesn’t reflect the values that are so central to the founding of our country,” Mr. Earnest said. “So I think this would be an appropriate venue for the president to make clear that Muslim Americans make a valuable contribution to the success of our country, and that the protections that allow Muslim Americans to worship God according to their traditions in this country are sacrosanct.”

The campaign rhetoric also has concerned White House officials who say it’s damaging to U.S. efforts to gain cooperation from moderate Muslims at home and abroad to fight extremist groups such as the Islamic State.

The choice of the Baltimore mosque has come under some criticism, primarily over a past imam, Mohammad Adam el-Sheikh, who was a member of the extremist Muslim Brotherhood in Sudan in the 1970s. He also has worked for an Islamic relief group that the Treasury Department designated as a terrorist organization in 2004.

Dr. M. Zuhdi Jasser, a Muslim who is vice chairman of the U.S. Commission on International Religious Freedom, said the mosque is “very concerning” and that the president’s decision to visit there is “disgraceful.”

Mr. Earnest said Monday that he “can’t speak to why this specific mosque was chosen,” other than it “represents the diversity of the Muslim population in America.”

“Hopefully that will be evident from the audience that the president speaks to,” he said. “We will have more on why this mosque chosen as the president prepares for his visit.”

In an interview last week, Mr. Obama said the Republican Party is moving too far to the right over issues including the Muslim refugees.

“You think about it — when I ran [in 2008] against John McCain, John McCain and I had real differences, sharp differences. But John McCain didn’t deny climate science,” Mr. Obama told Politico. “John McCain didn’t call for banning Muslims from the United States. The Republican vision has moved not just to the right, but has moved to a place that is unrecognizable.”

While the president has visited mosques abroad on official trips, his stop in Baltimore Wednesday will be the first time he’s visited a Muslim place of worship in the U.S. Mr. Obama, a Protestant Christian whose father and stepfather were Muslims, has faced persistent speculation that he is a Muslim.