WASHINGTON — Republican senators sent the White House a sharp message on Tuesday, warning that they were almost uniformly opposed to President Trump’s plans to impose tariffs on Mexican imports, just hours after the president said lawmakers would be “foolish” to try to stop him.

Mr. Trump’s latest threat to impose 5 percent tariffs on all goods imported from Mexico, rising to as high as 25 percent until the Mexican government stems the flow of migrants, has prompted some of the most serious defiance in the Republican ranks since the president took office.

Republican senators emerged from a closed-door lunch at the Capitol angered by the briefing they received from a deputy White House counsel and an assistant attorney general on the legal basis for Mr. Trump to impose new tariffs by declaring a national emergency at the southern border.

[Update: Trump calls off plan to impose tariffs on Mexico.]

“I want you to take a message back” to the White House, Senator Ted Cruz, Republican of Texas, told the lawyers, according to people familiar with the meeting. Mr. Cruz warned that “you didn’t hear a single yes” from the Republican conference. He called the proposed tariffs a $30 billion tax increase on Texans.