Congress and the president agreed to pass seven stopgap spending bills to fund government agencies through Feb. 15. This brings an end to the longest government shutdown in U.S. history. (Carolyn Kaster/AP)

Congress and the president reached a deal Friday, ending the longest government shutdown in U.S. history — at least for the next three weeks. President Trump came away empty-handed, with no money to build a border wall. The agreement handed a victory to the Democrats, who had insisted that they would negotiate over border security only after Trump and Senate Republicans agreed to reopen the government.

Technically, Congress and the president agreed to pass seven stopgap spending bills (known as “continuing resolutions”) to fund government agencies through Feb. 15. That gives House and Senate negotiators three weeks to hammer out a deal on homeland security — and on spending for the rest of the fiscal year, which ends Sept. 30. If they can’t do that, the government could close again when the stopgap bills expire.

Here’s how lawmakers and Trump reached the deal and what to keep an eye on in the weeks ahead.

1. Polarized parties playing a blame game

Today’s highly competitive and polarized parties can’t typically make deals by looking for areas of agreement. Such ideological sweet spots to anchor a deal are just too rare on most issues — especially one as polarizing as immigration.

Instead of searching for common ground, the parties play a blame game. Each party blames the other for unpopular policies while trying to dodge blame themselves. A party wins by successfully pinning more blame on the other party. The game ends only when one party decides that the costs to its reputation of refusing to fold are greater than the benefits of continuing to wage war.

That explains why this government shutdown — as well as closures in 1995 and 2013 — ended with one party claiming victory and the other getting little in return. In 2013, Republicans promised to block bills to fund the government until Democrats agreed to defund the Affordable Care Act. Observers pinned the blame on the GOP for the stalemate, and Democrats essentially got what they wanted at the bargaining table, including funding for Obamacare. In contrast, the short-lived shutdown last February over Democrats’ demands on behalf of “dreamers” (beneficiaries of the Deferred Action for Childhood Arrivals program) lasted just a few days because Democrats quickly folded when they realized public opinion was against them.

2. The public calls the shots

In a televised Oval Office meeting with House Speaker Nancy Pelosi (D-Calif.) and Senate Minority Leader Charles E. Schumer (D-N.Y.) in December, Trump famously said he would shoulder the blame for a government shutdown if the Democrats refused to fund a border wall. “I will be the one to shut it down. I’m not going to blame you for it.” Of course, the president did try to blame the Democrats, calling them captive to their radical base, soft on borders and crime, and indifferent to the humanitarian crisis brewing on the border.

But as Trump learned, a president doesn’t determine who wins or loses a blame game. That’s for the public to decide. As political scientist E.E. Schattschneider argued decades ago, “the spectators are an integral part of the situation, for, as likely as not, the audience determines the outcome of the fight.” In other words, politicians win messaging wars by securing broad public support for their positions.

This time, Democrats decisively won the messaging war. Polls overwhelmingly signaled that the public blamed Trump, not the Democrats, for the pain caused by the shutdown. Hardship stories of government employees working without pay, slowdowns at airports, degradation of iconic national parks and a lack of empathy from the Trump administration pushed the public to blame the president and the GOP. No surprise then — except in the Oval Office — that Senate Republican unity cracked while Democrats remained united behind their party leaders. What’s more, because he shouldered the most blame, Trump saw his approval slip roughly three points over the course of the shutdown.

Having lost the messaging battle, it’s no surprise that Trump failed to secure any money for the border wall. As in past shutdowns, the party perceived to be on the right side of public opinion faced little pressure to concede anything at the bargaining table.

3. What’s next?

Trump is an extremely weak position. Today’s turn of events only confirms what lawmakers have long suspected. As political scientist Matt Glassman argues, Trump repeatedly backs down from his public positions. Building on Richard Neustadt’s classic work on presidential power, that’s a problem for the president going forward. The players expect that, with enough pressure, the president will again back down.

What’s more, the president has already waved the white flag on funding a wall. Trump today threatened that if Congress won’t pony up $5 billion for a wall, he’ll declare a national emergency and try to build the wall without legislative authority. Many expect such a move to wind up in the courts or be delayed by foot-dragging as the military or Army Corps of Engineers looks for funds they can divert for a wall. Because few expect that ploy to work, lawmakers have little incentive to find ways to meet the president’s demand.

Finally, eyes will be on the House and Senate lawmakers assigned to negotiate a deal. But stay focused on Pelosi and Senate Majority Leader Mitch McConnell (R-Ky.). In polarized times, nothing big gets done without support of the party chiefs. Trump will always be a wild card, but neither political party wants to see the government shut down again, and Republicans, especially, are unlikely to want to shoulder such blame all over again.