Congress gave final approval on Friday to legislation that combines a two-year transportation measure with bills to extend subsidized student loans and revamp federal flood insurance, wrapping up a bruising session with measures that will be popular on the campaign trail.

The final $127 billion package angered fiscal conservatives and liberal environmentalists alike, but leaders in both parties — along with many rank-and-file lawmakers — wanted to put the issues behind them.

Exhausted members of both parties pointed to the legislation as a tonic for the ailing job market, as well as proof that an unpopular Congress could get something done. The House passed it by 373 to 52, the Senate by 74 to 19. All the no votes were by Republicans.

“When all is said and done, this bill is what it is,” said Representative Nick J. Rahall II, a West Virginia Democrat who was one of the senior negotiators. “It means jobs.”