The Muslim ban proposed by Republican presidential nominee Donald Trump is “not the America we want”, President Barack Obama has said.
Treating Muslim-Americans differently will only make the country less safe by increasing division between the West and the Muslim world, he said.
On Monday Mr Trump extended his ban plan to people from all countries with a terror history against the US.
He said the deadly Orlando nightclub shootings justified such action.
Forty-nine people were killed when Omar Mateen, a US national with Afghan parents, opened fire in a gay club early on Sunday.
Mr Trump said his proposal could be implemented through unilateral executive action, given the president’s power to “suspend entry into the country of any class of persons that the president deems detrimental to the interests or security of the United States”.
But on Tuesday at the US Treasury in Washington, a visibly angry Mr Obama launched his strongest assault yet on the man who is expected to be confirmed as the Republican nominee next month.
The president said the US had been founded on freedom of religion and having a “religious test” would be against the US Constitution.
He also noted that recent terror attacks in the US had been carried out by people born in the US.
Mateen was born in the same New York neighbourhood as Mr Trump.
The president also urged the US to reinstate the ban on assault weapons.
And he dismissed Mr Trump’s suggestion that he resign because he refuses to use the word “radical Islamic terrorism”.
“If we fall into the trap of painting all Muslims with a broad brush and imply that we are at war with an entire religion, then we are doing the terrorists’ work for them,” he said.
Mr Obama will visit the scene of the carnage in Orlando on Tuesday.
More on Trump’s policy platform
28 things that Donald Trump believes
Donald Trump’s foreign policy assessed
50 Trump supporters explain why