For her part, Ms. Pelosi, who turned 75 on Thursday, again demonstrated that even as the leader of a minority party that is sometimes restless for fresh leadership, she could win policy fights for Democrats while persuading them to compromise. Mr. Boehner lost just 33 Republicans on the bill, and only four Democrats voted no.

Democrats were pleased that the bill extended some of their favorite programs and did not attempt to roll back the Affordable Care Act, as Republicans have repeatedly tried to do. Republicans felt they had won because, as Mr. Boehner said, the bill made a start on “real entitlement reform” without the tax increases often sought by Democrats.

Under the bill, Medicare would pay doctors based on their performance, rewarding them for higher-quality work rather than the volume of services. The Children’s Health Insurance Program would be extended for two years, rather than the four years sought by Democrats. More money also would be appropriated for community health centers, with a restriction for abortion services.

To help offset the costs, some higher-income Medicare beneficiaries would be required to pay higher premiums for coverage of doctors’ services and prescription drugs. But about two-thirds of the costs would be added to the deficit. The Congressional Budget Office estimated that the bill would add $141 billion to federal budget deficits in the coming decade, compared with existing law.

Members of both parties went to the House floor on Thursday for what was officially a debate, but sounded more like a wedding, with lawmakers speaking of the measure as benefiting elderly Medicare patients, children and taxpayers.

“It’s not a perfect bill,” said Representative Ami Bera, Democrat of California, who is a physician. “But I came to Congress to put people first. I came to Congress to work across the aisle in a bipartisan way to put our country first.”