The House of Representatives relied heavily on Democrats to secure passage in a 277-151 vote. A large majority of Republicans voted against the measure, which did not meet conservatives' demands to cut off money to women's healthcare provider Planned Parenthood amid an abortion controversy.
The House also passed a companion bill aimed at restoring the Planned Parenthood defunding provision, but the Senate is not expected to act on it, effectively killing it.
President Barack Obama signed the spending extension into law later on September 30, the White House said in a statement.
Obama welcomed the news with a tinge of sarcasm in remarks to a group of progressive state legislators in Washington.
Earlier in the day, by a vote of 78-20, the Senate approved the legislation that was needed to keep the government running at current levels with the start of the new fiscal year on October 1.
The controversy over Planned Parenthood funding threatened a repeat of a 17-day shutdown in October 2013 that was prompted by Republican demands to deny federal funding for Obama's healthcare law, the Affordable Care Act.
House conservatives, cheered on by some Senate colleagues, had insisted that Planned Parenthood be punished for allegedly improperly selling fetal tissue harvested from abortions. The organization has denied the allegations.
The debate shifted dramatically last week when House Speaker John Boehner announced his resignation and said he would put the Senate's "clean" funding bill to a vote.
The funding extension aims to give congressional negotiators and Obama about 10 weeks to work out a longer-term budget deal and ease automatic spending constraints on military and domestic spending. Senate Majority Leader Mitch McConnell has said he would like to reach a deal with Democrats that sets funding levels for two fiscal years, through September 30, 2017.