By Kaitlan Collins, Phil Mattingly, Sarah Westwood and Betsy Klein, CNN

The three Republican senators outside the White House gate weren't on the list.

Hoping to stave off an embarrassing rebuke of President Donald Trump, Sens. Lindsey Graham of South Carolina, Ted Cruz of Texas and Ben Sasse of Nebraska decided to show up virtually unannounced to make a last-ditch effort Wednesday night to strike a bargain that would avoid an embarrassing defeat in the Senate over Trump's national emergency declaration.

But their surprise overture failed, and the following afternoon the Senate passed the resolution with 12 Republicans joining Democrats, setting Trump up for the first veto of his presidency.

The night before, the trio of GOP senators were initially stalled at the entrance, their names not precleared to enter the secure complex. By the time they made it inside, Trump was enraged at their antics, which fell in the middle of a family dinner.

"We just kind of barged in on his supper," Graham admitted to reporters a day later, as lawmakers were preparing to vote on a measure annulling the national emergency declaration Trump signed last month to secure border wall funding.

The White House is now reeling from a setback following the Senate passing the resolution, despite the pressure campaign it had waged for the last week. That a dozen GOP senators would buck the President was an outcome a group of Republican senators had been hoping to prevent as they crafted a compromise that would allow the national emergency to proceed while limiting a president's powers to declare one in the future.

Trump rejected such a measure midday Wednesday in a phone call with Senate Republicans during their weekly lunch. But believing he could still be convinced, Graham, Cruz and Sasse piled into a car to appeal to him in person.

The trio had made an unsuccessful attempt earlier in the afternoon to sit down with Trump, but White House aides said it was too late and didn't see the point in bringing them over. Trump had already told staff he was resigned to issuing his first veto after it became clear that enough Republicans would support the measure to overturn the declaration for it to pass.

Undeterred, the lawmakers went anyway. Graham phoned Trump while he was in the car on Pennsylvania Avenue to inform him that he and the other two Republican senators were en route.

Graham said the group "barged" into dinner and made clear that if the President would support a proposal from Republican Sen. Mike Lee of Utah to limit the length of national emergency declarations, that would minimize Republican defections "dramatically."

The lawmakers had found themselves in a tough position: Break with the President or vote against something they agree with. They wanted some kind of agreement that if they voted against the measure Thursday, then Trump wouldn't utilize his executive power like this again.

But instead of a change of heart, their entreaties were met with anger. Trump yelled at the group for interrupting him, according to people familiar with the matter.

The meeting went downhill fast, other sources said, as Trump grew frustrated at attempts to limit his ability to declare national emergencies in the future. A White House lawyer was brought in to point out problems with the idea and explain why it wouldn't work for the White House, a source said.

When the three senators sat down with Trump, it became clear they weren't presenting a single proposal -- Graham was there to discuss Lee's proposal, while Cruz pitched a separate idea to pull back the military construction funding portion of the emergency declaration. It was something, after consulting with the White House lawyer in attendance, the President rejected out of hand.

The overall meeting, the source said, was "just unproductive."

Graham, the President's closest ally in the Senate, struck a more optimistic note on Thursday. He told reporters the President had listened intently during their meeting.

"I said I don't expect you to give up any powers of the president that you think is necessary but if you could find a way to sit down and bridge the gap here prospectively it would be in everybody's best interest," Graham said.

"We'll see what happens," Graham added. "It may bear fruit."

And he may be at least partially right. Though Trump made clear both during his interrupted dinner and in the earlier phone conversation with senators that he would not support a proposal to limit future national emergency declarations to 30 days, he seemed to reverse course on Twitter Thursday.

"Prominent legal scholars agree that our actions to address the National Emergency at the Southern Border and to protect the American people are both CONSTITUTIONAL and EXPRESSLY authorized by Congress," Trump wrote. "....If, at a later date, Congress wants to update the law, I will support those efforts, but today's issue is BORDER SECURITY and Crime!!! Don't vote with Pelosi!"

Senate Republicans were caught off guard by Trump's tweet that he would support changes to limit his future authority on national emergencies, according to multiple Senate aides, but it did not appear to have a significant effect on the final vote count.

"Too little, too late," one senior GOP aide said. It might have swayed a few on-the-fence senators, but the resolution still passed with a dozen GOP defections.

Shortly after the President's tweet, Utah Sen. Mitt Romney announced he would support the resolution to terminate the national emergency, which kicked off a steady stream of GOP defections throughout the day.

The margin was still slightly better than some aides had feared. Trump had hoped the number of "yes" votes would stay below 60, aides say, a symbolic limit that he believes would save some embarrassment, though still require him to use his veto pen. There were 59.

In internal conversations, Trump had characterized the vote as a loyalty test, even though some of those who voted for it, including Lee and Republican Sen. Rand Paul of Kentucky, have proved to be allies on other issues in the past. Even as members of his staff were focused Wednesday on managing the Boeing plane crisis, Trump himself remained preoccupied with the looming vote, according to people who spoke with him.

He fired off tweets. He made direct appeals to lawmakers over the phone. And senators who attended a Wednesday meeting on trade also heard a bid from Trump on the national emergency, though at that stage he had already conceded the resolution would likely pass.

This story has been updated to include additional developments Thursday.