Islamophobia is on the rise in the United States and US presidential candidates have targeted Muslims during the election campaign, Turkish President Tayyip Erdogan said during a visit to the country.

Speaking on Saturday at the opening of a Turkish-sponsored mosque and religious complex outside Washington, Erdogan also said recent attacks in Brussels and Paris "cannot compare" to what countries such as Turkey and Pakistan had endured over the years in terms of violent attacks by hardline groups.

"Unfortunately, we are in a period of rising intolerance and prejudice toward Muslims in the United States and the world," Erdogan said. "It is absolutely unacceptable to make all Muslims pay the price for the pain and horror" of the attacks on America on September 11, 2001, he said.

"There are still people walking around calling Muslims terrorists. I am watching with bewilderment and astonishment that some candidates still defend this position in the current presidential election in America."

The Turkish leader was in the US mainly to participate in a nuclear summit in Washington.

"Thousands have come here to hear him speak," Al Jazeera's John Hendren, reporting from the mosque, said.

"There are Turkish flags here with the words 'I love Turkey' on them. He has generated some enthusiasm on an otherwise controversial trip."

ISIL discussed

On Thursday, US President Barack Obama reaffirmed the US commitment to Turkey's security during a meeting with Erdogan, while also discussing both countries' efforts to fight the Islamic State of Iraq and the Levant (ISIL, also known as ISIS), the White House said.

"The president extended condolences to President Erdogan on behalf of the American people for those killed and injured in today's terrorist attack in Diyarbakir, and reaffirmed the support of the United States for Turkey's security and our mutual struggle against terrorism," the White House said.

"The leaders also discussed how to advance our shared effort to degrade and destroy ISIL."

In a statement on Friday, Turkey's presidential office said the two NATO leaders discussed cooperation on resolving the refugee crisis and how partners in the fight against ISIL can ramp up their efforts.