The US government partial shutdown is ending after Republicans and Democrats voted for a temporary funding bill.
The Democratic leadership agreed to back the bill after accepting promises from Republicans for a debate later on the future of young illegal immigrants.
President Donald Trump, who signed the bill on Monday evening, took a swipe at Democrats.
It is the fourth temporary measure since October because Capitol Hill cannot agree a longer-term budget.
The spending bill passed the Senate by 81-18 and the House of Representatives by 266-150 earlier on Monday.
The so-called continuing resolution keeps the government funded until 8 February in the hope that Congress can reach a longer-term budget agreement in the meantime.
Thousands of federal employees who had been placed on temporary, unpaid leave since Saturday breathed a sigh of relief.
"It was essentially a lunch break," Tom Chapel, a scientist at the Centers for Disease Control and Prevention in Atlanta, Georgia, told Reuters news agency.
What are Republicans saying?
Republican Senate leader Mitch McConnell said his party had "come to an arrangement" to negotiate on the Democrats' calls for an immigration deal.
Democrats want protections from deportation for so-called Dreamers, more than 700,000 young immigrants brought to the US as children.
But Republicans had insisted no agreement was possible while federal government services were closed.
President Trump, a Republican, said in a statement: "I am pleased that Democrats in Congress have come to their senses.
"We will make a long-term deal on immigration if, and only if, it is good for our country."
Did Democrats 'cave'?
Democrats voiced scepticism of Mr McConnell's promise and some liberal groups are infuriated by the agreement to reopen the government.
Possible Democratic 2020 presidential candidates in the Senate - Elizabeth Warren, Kirsten Gillibrand, Cory Booker, Bernie Sanders and Kamala Harris - all voted against Monday's bill.
Senator Harris, of California, said it would be "foolhardy" to trust Mr McConnell's promise to take up an immigration bill in the coming weeks.
Another California senator, Dianne Feinstein, told The Hill, a political news outlet, she was "very disappointed" in the deal because there's no guarantee that Republicans would help Dreamers.
Democratic congressman Luis Gutierrez slammed his own party's senators after the vote saying: "They caved. They blinked. That's what they do."
On Twitter, "Democrats CAVED" was trending on Monday evening.
Senate Democratic leader Chuck Schumer accused President Trump of failing to help reach a deal.
"The great deal-making president sat on the sidelines," he said.
But many have expressed dissatisfaction with Mr Schumer's handling of the shutdown, which began on midnight on Friday.
"It's Schumer's job to lead and keep his caucus together to fight for progressive values, and he didn't do it," said Ezra Levin, co-executive director of the activist group Indivisible.
Stephanie Taylor, of the Progressive Change Campaign Committee, said: "Today's cave by Senate Democrats - led by weak-kneed, right-of-centre Democrats - is why people don't believe the Democratic Party stands for anything."
Who emerges as victor?
Anthony Zurcher, BBC News, Washington
The shutdown is over, but the immigration and budget battles rage on. Both sides will try to claim victory, with varying degrees of success.
Republicans are thrilled that - unlike past shutdown fights - they emerged relatively unscathed. Senate Majority Leader Mitch McConnell promised an open debate and vote on protections for so-called Dreamers, but in reality that could go by the wayside if, three weeks hence, Democrats force another shutdown.
Democrats, on the other hand, can claim that they took a confrontational stand - at least for a few days - on an issue dear to their base's heart. Whether that's enough to satisfy the progressive hard-liners and grassroots activists is in doubt, however. A key tell is that nearly every 2020 presidential hopeful among their number voted against re-opening. For them, Mr McConnell's guarantees are written in sand.
Meanwhile, Donald Trump was largely sidelined through the process. Democrats, and even some Republicans, complained he was impossible to pin down and unclear about his priorities. Still, a few days out of the spotlight may not have been all bad.
The American public will probably forget this long-weekend shutdown before too long. The next fight, looming only weeks away, might be different.
Why don't shutdowns happen elsewhere?
In parliamentary systems, a government that can't pay the bills doesn't last long.
In 2012, for example, the Dutch government couldn't agree a budget. The prime minister resigned, elections were held, and a new government formed.
Some countries don't even need a government to function.
After its 2010 election, Belgium went more than 500 days without elected leadership, but still avoided a shutdown.
Taxes were collected, workers were paid, and a caretaker government passed a budget.
In France - a semi-presidential system - the constitution sets out what happens when a budget isn't passed.
The government, it says, shall "make available by decree the funds needed to meet commitments already voted for".
Really, the question isn't why other countries don't shutdown. It's why the US does shutdown, even when there's money sloshing round the system.
That stems from 1980 and 1981, when US Attorney General Benjamin Civiletti strictly interpreted the 1884 Antideficiency Act.
He said, in the event of a funding gap, government agencies should suspend operations - until money was appropriated by Congress.