WASHINGTON -- President Barack Obama on Friday forcefully endorsed allowing a mosque near ground zero, saying the country's founding principles demanded no less.

"As a citizen, and as president, I believe that Muslims have the same right to practice their religion as everyone else in this country," Obama said, weighing in for the first time on a controversy that has divided New York City and the nation.

"That includes the right to build a place of worship and a community center on private property in lower Manhattan, in accordance with local laws and ordinances," he said. "This is America, and our commitment to religious freedom must be unshakable."

Obama made the comments at an annual dinner in the White House celebrating the Islamic holy month of Ramadan.

The White House had not previously taken a stand on the mosque, which would be part of a $100 million Islamic center two blocks from where nearly 3,000 people perished when hijacked jetliners slammed into the World Trade Center towers on Sept. 11, 2001.

Press secretary Robert Gibbs had insisted it was a local matter.

It was already much more than that, sparking debate around the country as top Republicans including Sarah Palin and Newt Gingrich announced their opposition. So did the Anti-Defamation League, a Jewish civil rights group.

Obama elevated it to a presidential issue Friday.

While insisting that the place where the twin towers once stood was indeed "hallowed ground," Obama said that the proper way to honor it was to apply American values.

"Our capacity to show not merely tolerance, but respect towards those who are different from us, and that way of life, that quintessentially American creed, stands in stark contrast to the nihilism of those who attacked us on that September morning, and who continue to plot against us today," he said.

Obama harkened back to earlier times when the building of synagogues or Catholic churches also met with opposition. "But time and again, the American people have demonstrated that we can work through these issues, and stay true to our core values and emerge stronger for it," he said. "So it must be and will be today."

New York City Mayor Michael Bloomberg, an independent who has been a strong supporter of the mosque, welcomed Obama's words as a "clarion defense of the freedom of religion."

But some Republicans were quick to pounce.

"President Obama is wrong," said Rep. Peter King, R-N.Y. "It is insensitive and uncaring for the Muslim community to build a mosque in the shadow of ground zero. While the Muslim community has the right to build the mosque, they are abusing that right by needlessly offending so many people who have suffered so much."