President Donald Trump says he is ready to issue a veto after the GOP-controlled Senate side sided with House Democrats to block his national emergency declaration over the U.S.-Mexico border.

A dozen Republican senators, including Pennsylvania Sen. Pat Toomey, voted Thursday in favor of the resolution to block the national emergency Trump declared last month in an effort to secure funding for barriers along the border. The final vote was 59-41.

Trump was prepared for a fight, remarking ahead of the vote that he would issue his first veto if needed.

“I am prepared to veto, if necessary,” Trump wrote on Twitter. “The Southern Border is a National Security and Humanitarian Nightmare, but it can be easily fixed!”

Here’s how we got here and what to expect next.

How and why is the national emergency declaration being challenged in Congress?

Declaring a national emergency gives a president wide-ranging and “greatly enhanced powers," according to the Brennan Center for Justice, a nonpartisan public policy and law institute. Trump is most interested in greater control over armed forces and military construction projects, according to the center.

» READ MORE: National emergency: What is it, and why did Trump declare one over the border?

On Feb. 15, Trump signed a funding bill that prevented another government shutdown but did not fulfill his request for $5.7 billion that would go toward building 200 miles of wall along the border. By declaring a national emergency at the same time, he hoped to side-step the lengthy process it takes to get laws passed in Congress to get the financial resources needed.

House Democrats introduced a resolution late last month to block the national emergency. House Speaker Nancy Pelosi called the declaration a “power grab by a disappointed President.”

“[President Trump’s] unlawful declaration over a crisis that does not exist does great violence to our Constitution and makes America less safe, stealing from urgently needed defense funds for the security of our military and our nation,” she said.

What’s the latest in Congress?

As expected, the Democrat-controlled House passed the joint resolution last month with a vote of 245-182. It’s now been approved by the GOP-controlled, where at least four Republican senators needed to cross party lines and vote in favor of stopping the declaration (12 senators ultimately did so).

Toomey, one of the Republicans who voted to block the national emergency, said that, while he “is completely supportive” of Trump’s push for the U.S.-Mexico border wall, he considered Thursday’s vote “a very important separation of powers issue," my colleague Jonathan Tamari reports.

Vice President Mike Pence appeared on Fox News Thursday morning, urging Republicans to stick with the president.

“A vote against the president’s national emergency declaration is a vote to deny the humanitarian and security crisis that’s happening at our southern border," he said on Fox & Friends. “So we’re urging every member of the Senate set politics aside, recognize that we have a crisis.”

What happens after the Senate votes?

Trump could step in with a veto, and has indicated he will do so. Congress could then throw out the veto, but only with a two-thirds vote in both chambers, and not enough congressional Republicans appear to be leaning toward blocking the declaration to overrule a veto.

Congress has overridden fewer than 10 percent of presidential vetoes, according to the Senate’s website.

“I don’t know what the vote will be, it doesn’t matter,” Trump told reporters later at the White House, NBC News reported. "I’ll probably have to veto and it’s not going to be overturned, and we’re going to have our whole thing.”

How else is the emergency declaration being challenged?

The declaration is being challenge not just legislatively, but legally, too. Sixteen states, including New Jersey and Delaware, filed a lawsuit last month, alleging that the move was unconstitutional.

“President Trump treats the rule of law with utter contempt,” said California Attorney General Xavier Becerra, according to the Associated Press. “He knows there is no border crisis, he knows his emergency declaration is unwarranted, and he admits that he will likely lose this case in court.”

Pennsylvania is holding off from joining the until it becomes clear whether Trump plans to use money appropriated for projects in the state, Attorney General Josh Shapiro said in February.

Additional lawsuits have been filed by organizations like the American Civil Liberties Union and the Center for Biological Diversity.

Congress’ potential move to side against the president could be used against him in court even with a presidential veto, according to Vox.

In an unexpected visit Wednesday, Republican Sens. Ted Cruz of Texas, Lindsey Graham of South Carolina and Ben Sasse of Nebraska also issued a plea to Trump for a “last-minute proposal aimed at satisfying concerns of senators” likely to vote alongside Democrats, according to the Washington Post.