Having reached a deal on a nearly $2 trillion deal to keep the government open, President Obama and congressional leaders tried to build support Wednesday for the massive bill, which hikes spending across government, thrilling Democrats, and extends a host of special interest tax breaks, exciting Republicans.

Racehorses and NASCAR racetracks, school teachers and college students, green energy companies and the big oil giants all made out well in the deal, reached overnight after weeks of negotiations. The chief loser, meanwhile, is the federal deficit, which grows by hundreds of billions of dollars under the terms of the tax deal.

Mr. Obama gloated over the agreement, saying he got nearly everything he wanted and gave up very little, only ceding ground in allowing two Obamacare taxes to be postponed and agreeing to lift the decades-old ban on exporting crude oil.

Republicans, meanwhile, said they were in too weak of a position to prevail over Mr. Obama on a giant list of grievances, including trying to reel in his expansive use of executive power, his new rules limiting greenhouse gas emissions and his plans to resettle 10,000 Syrian refugees in the U.S. this year.

“We’ve played the cards we were dealt as best as we could,” newly minted House Speaker Paul D. Ryan, Wisconsin Republican, told reporters Wednesday morning in explaining why he wasn’t able to win any of those changes.

Instead, Mr. Ryan said Republicans should be happy with the end of the oil export ban and with extending the dozens of tax breaks, predicting they would both spur new jobs and help keep the economy on track.

But many Republicans were not convinced, saying the deal deepens deficits and unravels the budget gains the GOP won during the previous four years without winning any of the restrictions they wanted to impose on Mr. Obama.

Sen. Jeff Sessions, Alabama Republican, said the measure was a “betrayal” of the trust conservative voters put in GOP leaders by giving them power last year. He said Congress should have at least reined in Mr. Obama’s refugee plans.

“There is a reason that GOP voters are in open rebellion,” Mr. Sessions said.

The new deal combines two big bills — an agreement to extend dozens of popular special tax breaks, totaling some $680 billion in lost revenue, and a full-year spending bill, which spends $1.149 trillion on basic government operations in fiscal year 2016, which ends Sept. 30.

The House will vote on the tax provisions Thursday and the spending provisions Friday, sending them as a joint package to the Senate for a final vote and an eventual presidential signature.

“We feel good about the outcome. We succeeded,” said White House press secretary Josh Earnest.

Even on one of the few setbacks for President Obama — the lifting of a ban on U.S. crude oil exports — Mr. Earnest said the loss was not particularly troubling because the U.S. already exports 4.3 million barrels of refined petroleum per day and another 500,000 barrels of crude oil via waivers of the ban. And in exchange for that loss, the spokesman said Democrats won the biggest spending hike in history on renewable energy.

Mr. Earnest praised Mr. Ryan, saying he made a “good faith effort” to work with the president. But the spokesman also said Mr. Ryan and his Senate counterpart, Majority Leader Mitch McConnell, were rightly afraid of being blamed for gridlock.

“Look, the other undeniable factor here is that Senator McConnell and Speaker Ryan didn’t want to preside over a government shutdown,” Mr. Earnest said.

The spending bill spans 2,009 pages, which works out to an average of nearly $572 million per page.

“I don’t think any of us are going to know what’s truly in it by the time it comes up [for a vote] Friday,” Rep. James P. McGovern, Massachusetts Democrat, chided his colleagues. He said those on both sides of the aisle are going to have to cast votes based on the statements of their leaders — putting them all in a tricky position.

Republicans managed to settle a few scores in the new massive spending bill, including blocking the IRS and the Securities and Exchange Commission from writing new campaign finance rules and demanding the State Department clean up its act after former Secretary Hillary Clinton’s unique email arrangement. They also cut several million dollars from the American contribution to the U.N. Population Fund, which has been a target of pro-life conservatives for years.

But the bill keeps most of the president’s priorities intact, and even boosts funding for them. After years of cuts, the IRS gets an additional $290 million next year.

The bill also spends $750 million in Central America, particularly on Mr. Obama’s strategy of trying to boost the economies and governments of the region, hoping it will stem some of the surge of illegal immigrant children who’ve jumped the border in recent years. It’s less than Mr. Obama sought, but does amount to at least somewhat of a congressional imprimatur of his plans.

The spending bill is months overdue, and lawmakers on both sides of the aisle vowed to try to do better next year — both in acting sooner and in trying to pass the dozen individual spending bills that are supposed to fund basic operations.

That process broke down this year when Senate Democrats gummed up the works in their chamber and an internal GOP dispute halted work in the House. It took a last-minute budget deal in October, which broke the 2011 debt deal and boosted spending on both domestic and defense priorities, to break the logjam and set the stage for this week’s final action.

The 233-page tax breaks bill, meanwhile, contains breaks for NASCAR racetrack owners, teachers who pay classroom costs out of pocket, college students paying tuition or fees, wealthy Americans who want to bequeath part of their money to charities and dozens of other special interests.

Also included is a permanent extension of the research and development tax credit, created by Congress in the early 1980s as a temporary boost to the slumping economy. It’s been extended 16 different times, but the new bill writes it into the tax code for good.

Congress is also delaying two key taxes designed to pay for Obamacare’s generous new benefits, upsetting the careful economics underpinning that law and deepening deficits even more.

Robert L. Bixby, executive director of the budget watchdog Concord Coalition, said the decisions amounted to “fiscal lunacy,” saying Congress spent all year tightening its belt only to blow down the doors in the final days.

Extending the tax breaks also contradicts the calls from presidential candidates in both parties, who have promised on the campaign trail to eliminate these kinds of loopholes and use the savings to lower rates.

But Republicans said that by setting these tax breaks out of bounds, they have narrowed the conversation next year and made it easier to get a big deal done.

“By passing this bill now, Congress will have the freedom in the new year to move forward with comprehensive tax reform that grows our economy,” House Committee on Ways and Means Chairman Kevin Brady, Congress’s top tax-writer, said.