Congressional Leaders on the Verge of Massive Deal.

Congressional leaders said they have essentially clinched an agreement on a massive $1.3 trillion spending bill to fund the government through September, staving off a shutdown if both chambers can act by Friday night.

Most major issues, including funding for a massive New York transportation project and the border wall have been resolved. And negotiators finally reached a deal to fix a snafu in the GOP’s tax law — the so-called grain glitch — that farm state lawmakers were seeking.

House and Senate leaders also agreed to add provisions related to gun safety — including popular bipartisan legislation to improve the national background check system — after meeting Wednesday morning. 

"We feel really good about where things are," Speaker Paul Ryan (R-Wis.) told reporters after the meeting with other top leaders. "So we're finalizing and expect to post something very soon. So, we feel like we're in a good place."

The Big Four — Ryan, House Minority Leader Nancy Pelosi (D-Calif.), Senate Majority Leader Mitch McConnell (R-Ky.) and Senate Minority Leader Chuck Schumer (D-N.Y.) — huddled Wednesday morning to hash out the final details with text expected to be posted in the afternoon. Pelosi insisted afterward there were still a "few language things to clear up" before the bill could be released.

"We're hopeful we'll be ready to go in a few hours," Schumer said. "We're feeling very good about this. We've accomplished many, many, many of our goals."

Congressional leaders are still hoping to avoid the need for a short-term spending bill to keep the government open for a few days beyond Friday. But if the spending bill is released Wednesday as planned, the House will likely vote on the measure Thursday, giving the Senate just one day to clear the deal before funding expires.

Under this timetable, any single senator could cause a brief government shutdown under Senate rules and push work into the weekend. Kentucky GOP Sen. Rand Paul has pointedly refused to rule out doing so.

Rep. Mike Simpson (R-Idaho) said a very short continuing resolution could be necessary to avoid a shutdown.

"I could see a CR for a day," he told reporters.

The bill provides nearly $1.6 billion for border security, but does not include any money for an increase in detention beds or federal deportation agents, a key priority for Democrats in the talks.

The deal includes $641 million for new fencing, including levees, but does not allocate money for a concrete wall, according to a source familiar with the agreement. The proposal also includes nearly $1.3 billion for other border security technologies.

Negotiators also agreed to a compromise of sorts on the Gateway project. President Donald Trump had vowed to veto the must-pass spending bill if it includes funding for the $900 million tunnel project, a top priority for Schumer and other New York and New Jersey lawmakers.

The bill doesn’t provide the specific funding for the project but does include funding increases for other federal transportation accounts, including Amtrak, that will allow tunnel construction to begin. And there will be more than $500 million available for Gateway this year that doesn’t require administration approval under the terms of the deal, and the project can apply for billions more, according to a source familiar with the negotiations.

"It’s troubling that we get a tunnel but we don’t get a wall," House Freedom Caucus Chairman Mark Meadows (R-N.C.) said, noting the border wall funding had previously been appropriated. "The last time I checked, the president didn’t make any promises about getting a tunnel at any of his campaign stops."

In a last-minute deal, congressional leaders also agreed to add provisions that would improve the national background check system for gun purchases and provide safety grants to schools to guard against future mass shootings.

As of midday Wednesday, negotiators were also still discussing adding language to rollback the so-called Dickey amendment, which prohibits the CDC from studying the impact of gun violence or advocating for gun control.

The gun issues remained a holdup in the talks throughout the week as Schumer pushed for more aggressive firearms restrictions, according to a source familiar with the talks. Sen. Chris Murphy, a co-sponsor of the "Fix NICS" bill with Sen. John Cornyn, personally made the case to Democratic leadership to accept the compromise, even if it didn’t go as far as they wanted, the person said.

House conservatives were also furious that GOP leaders agreed to include the "Fix NICS" provision in the bill. Members of the Freedom Caucus said they had been promised that the provision — favored by Trump and a bipartisan group of lawmakers — would only be considered alongside a gun-rights friendly measure to honor concealed carry permits across state lines.

"What we were told by our leadership is directly opposite what is happening today," Rep. Jim Jordan (R-Ohio) said during a roundtable with reporters Wednesday.

House Freedom Caucus leaders voted for the provision in December but only because it also included a rider allowing all conceal-carry permit holders to carry their weapons across any state lines. The bill would have essentially created a universal conceal-carry permit that would trump state laws that ban hidden firearms, Democrats argue. Members of the conservative group, however, were likely to vote against the massive spending bill anyway, so leadership probably doesn’t need their votes.

Congressional leaders also reached an agreement on one of the final sticking points, according to two sources familiar with the issue: a deal to fix a glitch in the GOP’s tax law in exchange for a temporary boost in the Low-Income Housing Tax Credit. The grain glitch lowers the tax bills of farmers who sell grain to cooperatives but at the expense of other farmers. Democrats at one point had sworn off allowing Republicans to iron out problems in their partisan tax bill passed last December.

In the end, congressional leaders ended up abandoning negotiations on many of the most controversial provisions lawmakers were trying to include in the must-pass bill — likely the last major piece of legislation to reach Trump’s desk before the midterms.

There is no agreement to protect so-called Dreamers, as Democrats had initially sought, or cuts to funding for sanctuary cities, as Republicans had wanted.

An effort to loosen campaign finance restrictions on parties coordinating with candidates, led by McConnell, was also dropped from the bill, according to a source familiar with the negotiations.

Lawmakers also gave up on efforts to stabilize Obamacare markets through subsidies known as cost-sharing reduction payments after both sides failed to settle a dispute over restrictions on abortion.

The deal does not include a provision to protect special counsel Robert Mueller if he’s fired by Trump — as Schumer and Pelosi had wanted — but it does provide for an increase in funding to fight Russian hacking ahead of the November elections.

The proposal includes an increase in the FBI’s budget to combat Russia cyberattacks this year and provides an additional $380 million for technology grants that will allow states to secure election systems.

Sarah Ferris and Kyle Cheney contributed to this report