The House approved the measure late Thursday by 219-206.
The compromise bill keeps agencies funded through next September.
Many conservatives opposed it because it did not block Obama's recent executive actions on immigration. A large majority of House Democrats opposed it because of provisions easing some restrictions on banks and allowing higher political contributions by big donors.
Obama backed the bill and called wavering Democratic lawmakers to persuade them to help it pass.
The bill must now be approved by the Democratic-run Senate.
Funding for federal agencies was expiring at midnight. Lawmakers were ready to pass short-term legislation keeping government doors open.