Jonathan Ernst / REUTERS Senator Bob Corker (R-TN) jokes with Senator John Hoeven (R-ND) at the U.S. Capitol in Washington, June 20, 2013.

It required hours of late-night haggling, heated disputes and a wonky economic white paper to emerge as an eleventh-hour savior. But Senate negotiators announced an agreement Thursday on an amendment that stiffens security along the southern border as part of a rewrite of U.S. immigration laws, clearing aside a primary obstacle and paving the way for passage through the chamber.

The deal, which Republican Senators John Hoeven and Bob Corker hashed out with the original architects of the bill, would strengthen the legislation’s security and enforcement policy, a sticking point for a cadre of GOP members whom its sponsors sought to win over. “It has the ability, if passed, to bring a bipartisan group together on immigration reform,” Corker predicted when the measure was unveiled on the Senate floor Thursday afternoon.

Supporters have sought to garner 70 votes for the legislation — a splashy figure they argue would amp up the pressure on the Republican-controlled House. Now they seem likely to approach or exceed that tally. But the political victory comes at a hefty cost.

(MORE: Senate Close to Crucial Border Deal)

The so-called border “surge” amendment — a coinage that borrows from John McCain‘s label for the influx of troops that bolstered the flagging U.S. effort in Iraq — would roughly double the number of agents patrolling the U.S.-Mexico border, from 18,500 to nearly 40,000. It would require 700 miles of fencing to be erected along the 1,900 mile border. And it would require employers to adopt a system to verify workers’ status, as well as establishing a mandatory system to track entries and exits at international airports and seaports where customs officials are deployed.

It’s hard to say how much it will cost, because legislative language hasn’t been unveiled. But it will be significantly more than the $6.5 billion already set aside for border security in the underlying bill.

“Americans want immigration reform – of that there is no doubt. They want us to get it right,” said Hoeven. “We secure the border, but we also take away the incentive to come across.” Under the plan, Congress must verify the conditions have been met within 10 years, before immigrants are eligible for green card status.

Navigating the delicate line between Republican demands for tougher border security and Democrats’ desire to preserve the pathway to citizenship proved tricky. As the Senate was voting to table a border amendment put forth by Texas Republican John Cornyn, members were hashing out the final details of the alternate proposal. First floated late last week, negotiations kicked into overdrive behind the scenes during the past 72 hours.

(MORE: Boehner in a Bind on Immigration)

Hoeven and New York Senator Chuck Schumer, the Democrats’ lead dealmaker, had a long phone conversation Tuesday that Schumer euphemistically described as “spirited.” That day, Lindsey Graham, one of the top negotiators on the Republican side, suggested the fate of the bill could hang in the balance. “We needed a rock solid requirement,” says a Republican Senate aide briefed on the talks, “done in a way that didn’t alienate Democrats.”

The knot was unraveled late Tuesday by an economic analysis of the bill, issued by the nonpartisan Congressional Budget Office (CBO), that found it would save nearly $200 billion over the next decade, as well as an additional $700 billion between 2024 and 2033. With cost concerns allayed by the CBO report, negotiators felt free to put $30 billion from the measure’s estimated savings toward an additional 20,000 border patrol agents.

Democrats were keen to ensure that the concessions on border security would be their last. They didn’t want to “open up a can of treats two days later on something else,” says a Democratic Senate aide close to the discussions. By Thursday afternoon, they appeared satisfied, even though the process of drafting the legislation was yet to wrap up.

“Barring something unexpected, we’re extremely enthusiastic that a bipartisan agreement is at hand,” Schumer said, hailing the bipartisan support for the amendment as a “huge breakthrough” which augurs a “a strong, bipartisan final vote.”

Republican Senator Marco Rubio, a member of the Gang of Eight who gave peers jitters by skewering the bill’s border provisions, spoke in favor of the deal. Earlier Thursday Republican Mark Kirk of Illinois announced he would support the legislation, and Nevada Republican Dean Heller, a swing vote, told reporters he would back it if the border amendment was incorporated.

(MORE: Border Security: Will it Block a Final Deal on Immigration?)

Corker estimated the deal would add at least 15 Republicans to the positive side of the ledger, likely pushing it over the 70-vote bar. But the boost didn’t come cheap.

“It’s nonsensical from a policy perspective,” says Angela Kelley, vice president for immigration policy at the left-leaning Center for American Progress. “The CBO score gave them the dollars to spend. It’s incredibly costly. I don’t know if it’s what’s actually needed at the border.”

Dan Stein, president of the Federation for American Immigration Reform, which opposes the bill, panned the amendment as “nothing more than a fig leaf designed to convince the American people that our immigration laws will be enforced in the future in exchange for granting amnesty to illegal aliens now.” The deal’s border security strategy requires a vast array of bells and whistles: observation towers, helicopter surveillance, seismic imaging and infrared systems, not to mention the drones that have already begun to patrol the border. But “there is little in this amendment,” Stein argued, “that should give the American people confidence that a new surge of illegal immigration will not occur over the next decade.”

Even if the deal is questionable from a policy perspective, proponents of immigration reform recognized the need to strike it. “There is a degree of certainty that this amendment brings about what the final vote is going to look like,” Kelley says. “That degree of comfort and security is really important, and they were smart to reach the agreement that they did.”

PHOTOS: Fatal Frontier, The Perils of Crossing the Rio Grande