The House of Representatives earlier backed the bipartisan agreement, hours after the Senate voted 81 out of 100 in favour, with Democrats stumping up 33 of the votes.
The deadlock saw federal employees off work without pay and national landmarks including the Statue of Liberty closed to the public.
Republicans needed 60 votes to unlock the funds, but with only 51 of the 100 Senate seats they were reliant on Democrats to get the vote through.
Democrats agreed to drop their objections in return for a Republican assurance to look at the Deferred Action for Childhood Arrivals (DACA) programme to protect the so-called ‘Dreamers’.
Senate Majority Leader Mitch McConnell agreed to debate the issue in the coming weeks.
The programme – which shields more than 700,000 immigrants who entered the US illegally as children – is scheduled to end in March, following an order from President Trump last year.
However, the deal to end the shutdown gives no assurances that the Dreamers can stay in the country and has been criticised by immigration activists and some Democrats.
President Trump said he was pleased the Democrats had “come to their senses” but that he would only make a long-term deal on immigration “if and only if it’s good for our country”.
White House press secretary Sarah Huckabee Sanders said the President’s focus was now on border security and that any deal on the Dreamers would be tied to funding for border security, which includes Mr Trump’s planned wall.
Sky News US Correspondent Mark Austin said: “It seems to be the Democrats who have blinked here.
“The issue of the children of illegal immigrants has been knocked down the road for about three weeks.
“There is a commitment from Republicans to try to do something about it, but no guarantee that they will.
Democrats may say Trump “sat on the sidelines” . But he sat on the sidelines and won ! Dems backed down . #GovermentShutdown
— Mark Austin (@markaustintv) January 22, 2018
“If an agreement is reached it would have to then pass through the House of Representatives, before being signed by Donald Trump, who is well known for saying one thing and doing another.
More from United States
Turkey intensifies offensive against US-backed Kurds
Democrats ‘blink first’ in shutdown standoff
RECAP: Senate approves deal to end shutdown
Hundreds of thousands off work as US government shutdown enters third day
Fascist fighters or criminals? On the streets with Portland’s Antifa group
Women’s marches: ‘We’re not taking it anymore’
“Anything could happen. It’s not a done-deal for the Democrats, they have merely bought themselves some more time.”
If no agreement is reached by 8 February, it will go automatically for legislation in the Senate, where it will then be voted on.