WASHINGTON — President Trump stunned Republicans on live television Wednesday by embracing gun control and urging a group of lawmakers at the White House to resurrect gun safety legislation that has been opposed for years by the powerful National Rifle Association and the vast majority of his party.

In a remarkable meeting in the Roosevelt Room, the president veered wildly from the N.R.A. playbook in front of giddy Democrats and stone-faced Republicans. He called for comprehensive gun control legislation that would expand background checks to weapons purchased at gun shows and on the internet, keep guns from mentally ill people, secure schools and restrict gun sales from some young adults. He even suggested a conversation on an assault weapons ban.

At one point, Mr. Trump suggested that law enforcement authorities should have the power to seize guns from mentally ill people or others who could present a danger without first going to court. “I like taking the guns early,” he said, adding, “Take the guns first, go through due process second.”