WASHINGTON — After years of dysfunction and abysmal public approval ratings, a chastened, even beaten-down Congress on Friday passed a $1.8 trillion package of spending and tax cuts with remarkably little rancor.

The sweeping deal was the product of a convergence of forces: Speaker Paul D. Ryan’s deftness in pacifying rebellious conservatives, the recognition by Republicans that a government shutdown could cripple them in the races for the White House and Senate and a recovering economy that helped end an era of austerity.

The relatively swift passage of the prodigious year-end package — by wide margins in the House and in the Senate — in many respects showed lawmakers bowing to the hard realities of a divided government.

President Obama quickly signed the measure, praised Mr. Ryan for his work and acknowledged the sacrifice of his predecessor as speaker, John A. Boehner, for also making the accord possible.