WASHINGTON — Inside a pink-hued hideaway office in the basement of the Capitol last month, Senator Christopher S. Murphy, Democrat of Connecticut, did something unusual for the start of a high-stakes legislative negotiation: Instead of a wish list, he came with a blacklist.
Two days earlier, an 18-year-old man had walked into an elementary school in Uvalde, Texas, and gunned down 19 elementary school students and two teachers, sending Mr. Murphy to the floor to beg his colleagues to end a vicious, decades-long cycle of inaction on gun safety and finally do something.
Now, sitting with his fellow Democrat, Senator Kyrsten Sinema of Arizona, and two conservative Republicans, Senators John Cornyn of Texas and Thom Tillis of North Carolina, to try to hammer out a compromise, he did not even bother mentioning the sweeping gun control measures he and his party had long demanded.
There was no talk of banning weapons or ammunition or of implementing a nationwide red flag law to allow guns to be taken from people deemed too dangerous to have them — all proposals that Republicans had staunchly opposed.
“I’ve got a pretty clear sense of what can get 60 votes,” Mr. Murphy said in an interview, referring to the threshold to move a bill past a Senate filibuster — and those proposals could not.
Less than a month after that huddle in Ms. Sinema’s Capitol retreat, Congress gave final approval on Friday to legislation aimed at keeping firearms out of the hands of dangerous people, breaking through a seemingly intractable political stalemate and taking the first substantial step in nearly three decades to toughen gun laws.
The measure, which President Biden signed into law on Saturday, was the product of weeks of intensive private talks that were galvanized by tragedy, fraught with political risk and punctuated with near collapses.
The National Rifle Association was deeply involved in drafting the bill, although the gun rights group ultimately opposed it, as was Everytown, the nation’s leading gun safety group. Their improbable pairing mirrored the unlikely bipartisan coalition of senators that forged the compromise, beginning not with lofty hopes of a historic deal, but by checking their respective priorities at the door.
“We really started with the idea of what we weren’t going to negotiate,” Mr. Tillis said in an interview.
This account of how the bill came to be was provided by more than a dozen lawmakers, aides and officials involved in the negotiations, several of whom spoke on the condition of anonymity.
The mood in the country and in Congress had shifted after Uvalde and a racist massacre days earlier in Buffalo that killed 10 Black people, creating a brief window in which both sides felt the need to take action to respond.
“There’s a couple of ways to do things around here: One is if you want a result; the other is if you just want to make a political statement,” Mr. Cornyn said this week. He added, “I think the Democrats wanted to get a result and we wanted to get a result, so this is what we came up with.”
Mr. Murphy’s first challenge was persuading his side to skip the political statement.
Senator Chuck Schumer, Democrat of New York and the majority leader, faced pressure from progressives to force a vote on strengthening background checks, a broadly supported step that most Republicans nonetheless opposed and did not have the votes necessary to pass.
In a phone conversation with Mr. Schumer, Mr. Murphy advised against a “show vote” but was pessimistic about the chance for any bipartisan deal. There was a “5 percent chance,” Mr. Murphy told Mr. Schumer, but it was worth a try.
He reached out to Republicans he thought might be amenable, including Senators Susan Collins of Maine and Patrick J. Toomey of Pennsylvania — the only two remaining Republicans who had supported a failed background checks bill in 2013 — and Mr. Cornyn, a longtime friend with whom he had worked in 2018 to make modest improvements to the federal background checks system.
Then Mr. Murphy texted Ms. Sinema after seeing her quoted saying she wanted to talk with Democrats and Republicans to see if there was anything Congress could do to protect frightened children nationwide.
“Are you serious?” he typed out on his phone. Ms. Sinema responded that she was.
Republicans, too, were realizing they needed to act. Senator Mitch McConnell, Republican of Kentucky and the minority leader, announced that he would dispatch Mr. Cornyn, a loyal ally, to monitor the talks, giving him both visibility into the negotiations and some degree of control over their direction.
Republicans made sure the N.R.A. was involved, knowing that while the group was unlikely to back any compromise, its vocal opposition could quickly kill any hope of a deal.
When Ms. Sinema, whose first job was at a domestic violence shelter, brought up the idea of tightening a federal ban against domestic abusers buying guns to include intimate partners as well as spouses, the N.R.A. pushed back, insisting that boyfriends could eventually regain their ability to purchase firearms.
When Democrats agreed that the ban should disappear after five years for first-time offenders who committed misdemeanors but otherwise had clean records, the N.R.A. sought to extend that to other domestic abusers, a step that would have loosened current law. Democrats, who were being advised by Rob Wilcox, the federal legal director for Everytown, refused.
“We weren’t going to sign onto that, and at that point, everybody became wise to what they were trying to do,” said John Feinblatt, Everytown’s president.
Mr. Murphy and Ms. Sinema were simultaneously meeting with a broader group of senators in both parties, cobbling together eight other centrists and veterans of past failed efforts at gun safety deals. None of the Republicans was facing re-election, giving the group more political latitude to act without fear of retribution from voters in November’s midterm elections.
By June 12, 10 Republicans and 10 Democrats publicly announced their outline for a deal that would enhance background checks for younger gun buyers, incentivize states to enact federal “red flag” laws to temporarily confiscate guns from dangerous people, close the so-called “boyfriend loophole” for domestic abusers and pour federal money into mental health and school security. The size and makeup of the group suggested that the measure would be able to muster the 60 votes necessary to advance in the evenly divided Senate.
But the job of turning an outline into legislative text was fraught, and the compromise nearly fell apart in the process.
Senators wrestled with an array of sticking points, sometimes over Thai food or wine Ms. Sinema brought from a Texas-born winemaker.
They debated who would count as an intimate partner in the domestic violence provision. Republicans were concerned that the legislation could be used to target decades-old past relationships and pressed for assurances that those barred from buying guns under the provision would be given due process.
With time running out for a deal late last week, a visibly frustrated Mr. Cornyn abruptly left a negotiating session on Capitol Hill to catch a late-afternoon flight home to Texas and appeared ready to throw in the towel.
“I’m done,” he declared as he left the meeting. “Now they know where I stand, and so far there is no agreement.”
Mr. Schumer, who estimated that he had spoken with Mr. Murphy “200 times in 10 days” during the talks, gave his dejected colleague a pep talk.
“I said, ‘I know things look bleak. You’ve just got to keep trying,’” Mr. Schumer said in an interview.
Back home in Texas, Mr. Cornyn came face to face with the political risks of cutting a gun safety deal with Democrats. At the Republican convention in Houston, he was booed and heckled loudly, with some in the audience chanting “no red flag.”
“The time that I was most nervous, honestly, was when I read the press coverage of Senator Cornyn at his state convention,” said Senator Martin Heinrich, Democrat of New Mexico and a member of the negotiating group.
But Mr. Cornyn stayed at the table. He had good reason to do so.
A week earlier, he and Mr. McConnell had commissioned a poll of 1,000 gun-owning households across the country and found that most supported the key elements of the emerging bill. A solid majority backed increasing federal funding for states to maintain or implement red flag laws, and more than 80 percent supported closing the boyfriend loophole and allowing law enforcement to have more time to examine juvenile and mental health records.
Mr. McConnell would later tell reporters Republicans saw a clear political incentive to back the bill, which he did along with 14 other members of his party.
On Tuesday evening, as the bill cleared the first hurdle to passage, Ms. Sinema and Mr. Cornyn fist-bumped on the floor.
“Thank you for not listening to the naysayers and the critics, and those who would spew disinformation and outright lies about what we’re doing here,” Mr. Cornyn declared after the Senate passed the bill on Thursday night, as gun violence survivors listened from the gallery above.
On Thursday night, as they waited for the final vote to close, Ms. Sinema turned to Mr. Cornyn with a challenge.
“What’s next, John?” she said.