The US Senate has agreed a $1.2tn spending package that will fund the US government through September. Legislators narrowly averted a partial shutdown of the government with minutes to go before a midnight deadline. While votes on a series of amendments are expected to continue for several hours, the agreement means that there will be no lapse in funding to key government departments. It should be ready to be signed by President Joe Biden on Saturday. Democrat Senate majority leader Chuck Shumer said it had not been easy, but "our persistence has been worth it". "It is good for the American people that we have reached a bipartisan agreement to finish the job," he said on the Senate floor. The legislation will bring an end to months of acrimonious wrangling between the two main parties. The White House said early on Saturday that the US Office of Management and Budget had ceased shutdown preparations because it was confident Congress would imminently pass the bill and President Biden would sign it into law. The bill has already passed the House of Representatives, with a final vote of 286 to 134 - narrowly above the two-thirds majority needed. All but 23 Democrats backed the legislation, while 112 Republicans voted no. A small but vocal group of conservatives had opposed proposed increases in government spending and called for new legislation that would include US immigration law changes aimed at addressing a surge of undocumented migrants at the US southern border. Congresswoman Marjorie Taylor Greene of Georgia filed a motion to force an election for a new House Speaker and replace Mike Johnson of Louisiana over his endorsement of the package. The House budget vote on Friday continues the trend in recent government-funding fights of Democrats joining some Republicans to approve legislation to avert a shutdown. Unlike recent votes, however, a majority of House Republicans opposed a funding bill negotiated by their own party.