This post was adapted from an Associated Press article by Erica Werner and David Espo.

After days of contentious debate over a pathway to citizenship, guest workers provisions and government aid to non-citizens, a far-reaching bill to remake the nation’s immigration system won Senate committee approval last night — but only after the the panel decided not to extend immigration rights to same-sex married couples.

In a dramatic conclusion to three weeks of very public wrangling, Judiciary Committee Patrick Leahy announced that he would hold back on an amendment to extend immigration rights to same-sex married couples. That provision, which had a support of a majority of committee members, would have unraveled the politically sensitive compromise crafted by the Senate’s so-called “Gang of Eight.”

Without the gay rights provision, the committee then approved the bipartisan compromise package on a 13-5 vote, with Republicans John McCain, Jeff Flake and Orrin Hatch joining all ten committee Democrats.

Texas Sens. John Cornyn and Ted Cruz voted against the carefully crafted deal.

Until Leahy began speaking on the issue to a hushed hearing room Tuesday evening, it wasn’t clear how the matter, which had hovered over the three weeks of committee sessions to review the legislation, would play out.

Leahy had been under pressure from gay groups to offer the amendment, which would allow gay married Americans to sponsor their foreign-born spouses for green cards like straight married Americans can. But Republican supporters of the bill warned that including such a measure would cost their support. As the committee neared the end of its work, officials said Leahy had been informed that both the White House and Senate Democrats hoped he would not risk the destruction of months of painstaking work by putting the issue to a vote.

“I don’t want to be the senator who asks people to choose between the love of their life and the love of their country,” Leahy said, adding that he wanted to hear from others on the committee.

In response, he heard a chorus of pleas from the bill’s supporters not to force a vote that they warned would lead to the collapse of Republican support and the bill’s demise.

“I don’t want to blow this bill apart,” said Sen. Dianne Feinstein, D-Calif., the first to speak up.

“I believe in my heart of hearts that what you’re doing is the right and just thing,” said Sen. Richard Durbin, D-Ill. “But I believe this is the wrong moment, that this is the wrong bill.”

Sens. Chuck Schumer, D-N.Y., and Al Franken, D-Minn., added their voices, and Leahy announced that, “with a heavy heart,” he would withdraw his amendment.

Gay rights groups voiced outrage, and the issue is certain to re-emerge when the full Senate debates the legislation. But it is doubtful that sponsors can command the 60 votes that will be needed to make it part of the legislation.

In the hours leading to a final vote, the panel also agreed to a last-minute compromise covering an increase in the visa program for high-tech workers, a deal that brought Hatch over to the ranks of supporters.

Under the bill, the number of highly skilled workers admitted to the country would increase greatly, but there were also protections aimed at ensuring U.S. workers get the first shot at jobs, and high-tech companies objected to some of those.

Under the deal, companies in which foreign labor accounts for at least 15 percent of the skilled workforce would be subjected to tighter conditions than businesses less dependent on H-1B visa holders, and requirements on recruiting and hiring and firing of U.S. workers would be relaxed.

In defeat, opponents said they, too, wanted to overhaul immigration law, but not the way that drafters of the legislation had done.

Sen. Charles Grassley, R-Iowa, recalled that he had voted to give “amnesty” to those in the country illegally in 1986, the last time Congress passed major immigration legislation. He said that bill, like the current one, promised to crack down on illegal immigration, but said it had failed to do so.

“No one disputes that this bill is legalization first, enforcement later. And that’s just unacceptable to me and to the American people,” he said.