Thirty minutes into debate in the House on Senate Bill 7, Dallas Democrat Rafael Anchia had Briscoe Cain, the Republican chairman of the Elections Committee, boxed in a rhetorical corner. Democrats were trying to show that the bill was nakedly partisan voter suppression meant to justify Donald Trump’s “big lie” that the 2020 presidential election was stolen. Anchia had picked on a clause in Cain’s bill, “purity of the ballot box,” that originated in the Reconstruction era as a justification to keep Black Texans from voting. He had pressed the representative from Deer Park into bashfully admitting that he was ignorant of the history of the term—a small win at least on Twitter, where the exchange went viral.

But the victory was short-lived. Forty-five minutes later, the first Texas House vote on the bill—concerning an amendment by Dallas Democrat Jessica González that would have stripped all the text from the legislation—showed the futility of the Democrat’s fight. The amendment went down 80–65, on a partisan vote with one Republican, San Antonio’s Lyle Larson, breaking from his party to support it. Democrats had filed 133 other amendments and were prepared to fight all night, but House Republicans had the votes to crush all of them.

Behind the main chamber, however, out of public view, another group of Democrats was fighting to gain concessions. Three members of the party had joined five Republicans in a conference room to negotiate substantial changes in the bill, including ones to lessen proposed criminal penalties for unintentional voter fraud and to protect caregivers of the disabled and elderly from being prosecuted for what otherwise would be the new crime of helping someone to vote. The Democrats knew they could not stop passage of Senate Bill 7, but felt they could make it “less bad.” The prospect of having to repeatedly defend the bill against allegations of racism, and of potentially providing testimony that could be used in a civil rights lawsuit invalidating the bill, made Republicans receptive to negotiations.

Talks had begun informally the previous day with overtures of compromise in a meeting led by Speaker Dade Phelan’s right-hand floor manager, Representative Dustin Burrows of Lubbock. Unlike Lieutenant Governor Dan Patrick, whose chamber had passed an “election integrity” bill so onerous that it was immediately denounced nationally as voter suppression, Phelan had to consider compromise. Patrick is elected statewide and can exclude Democrats from lawmaking without fear of retribution; the Speaker is elected by the membership of both parties in the House, and compromise is a key to keeping a majority coalition together.

But when Anchia, Black Caucus chair Nicole Collier, and Democratic caucus chair Chris Turner showed up in mid-afternoon on Thursday, they were met by a small group of seemingly hostile Republican representatives. Cain and Gonzalez, the vice chair of the Elections Committee, had been excluded from the meeting because they were considered to be lightning rods. The Democrats present had handed over a copy of SB 7 that was redlined with objections. Republican Andrew Murr of Junction flipped through the 27-page document rejecting one proposed change after another.

The meeting dissolved quickly. The Democrats left angry, feeling as if they had been set up. The Republicans in the room felt as though they had been made partisan targets. One told me that it was time for “cooler heads” to gather to “fix the problems instead of politically posturing.”

Burrows had not been in the meeting and when he learned of its collapse, he immediately started trying to put it back together. He asked for help from Edinburg Democrat Terry Canales, who in turn enlisted El Paso Democrat Joe Moody, the House speaker pro tempore. Neither Canales nor Moody were intimately familiar with the bill, so Moody grabbed Elections Committee member John Bucy, of Austin, off the floor. They all headed for the West Conference Room.

Moody says he went into the meeting feeling haunted by a similarly contentious fight over a bill in 2017. That year, Republicans had drafted SB 4, which was set to outlaw sanctuary cities, which decline to cooperate with federal immigration authorities who seek to deport undocumented immigrants who are held in county jails. Democrats had prepared more than 150 amendments and planned to spend the night of debate shaming Republicans on the floor, even if they knew they didn’t have the votes to pass the amendments. In retribution, Republicans filed an amendment of their own, to add a provision giving police the power to demand proof of legal residency from suspected undocumented immigrants. It was a provision many believed would lead to racial profiling. The “show me your papers” amendment promptly passed, as did the bill at large. Democrats couldn’t even claim a moral victory. “I was in all those rooms on SB 4, and I remember the feeling when it fell apart,” Moody recalled for me. “You got to learn the lessons from mistakes like that.”

Moody saw the same potential debacle approaching in the voting-restriction bill this year. Even though the House version was less onerous than its counterpart in the Senate, the bill still would have enhanced jail penalties for voting crimes that are most often committed through ignorance of the rules. And it would have made it a state jail felony for any local election official to distribute a vote-by-mail application to a voter who did not request it, as Chris Hollins, then the Harris County clerk, tried to do last year. It wasn’t legislation Democrats could support.

But the party didn’t have the votes to block the bill, because passing “election integrity” measures is an important vote for the GOP caucus. A Texas Tribune poll from February found that 73 percent of Texas Republicans believe that last year’s election results did not accurately reflect the legal votes that were cast, and a majority of Republicans in an April survey supported some of the restrictions in the Senate bill. The question for Moody and his Democratic colleagues was how to limit damage.

The second round of negotiations started about an hour before the full House began debate on SB 7 at 6:30 p.m. Thursday. Many Democrats on the floor wore black face masks emblazoned with “Good Trouble,” in honor of the late civil rights icon John Lewis.

The mood in the second negotiation was completely different from that of the midday meeting. Bucy, Canales, and Moody sat down with Republicans Murr, Brooks Landgraf of Odessa, Morgan Meyer of Dallas, and Stephanie Klick, a former chair of the Tarrant County Republican Party who had headed the House Elections Committee in 2019 when similar legislation was considered. This time, Burrows also sat in on the meeting, signaling the Speaker’s desire for compromise.

The Republicans wanted to avoid a divisive floor fight, and a demonstration of cooperation could work to their advantage in court. (There are already at least six challenges to the election bill Georgia passed in March, and the Harris County commissioners voted last week to file a lawsuit over any restrictive legislation the Lege passes.) The GOP representatives were joined by an attorney, Elizabeth Alvarez Bingham, the former vice chair of the Dallas County Republican Party. Bingham sits on the board of the American Civil Rights Project (formerly known as the Equal Voting Rights Institute), which unsuccessfully sued Dallas county commissioners in 2015, alleging that they discriminated against white voters by gerrymandering municipal districts to favor minorities. But Bingham, an election law litigator, was instrumental in urging the Republican negotiators to accept most of the proposed changes to the bill, Democratic negotiators told me.

The negotiations had made progress by a quarter past eight, but the leaders needed time to continue without the bill actually being debated further on the floor. Under guidance from his caucus, freshman Dallas Democrat John Turner called a point of order, arguing that the bill violated an obscure House rule. Members in the meeting knew the legislative maneuver was unlikely to kill the bill, but it would provide the needed delay for negotiations to keep going.

Over the course of the negotiation, which lasted well past midnight, Democrats earned concessions on about three quarters of their requests to water down the bill. They ensured that the mere act of violating a voting rule would not be regarded as a crime unless the person who committed the infraction knew he or she was breaking the law. (This could retroactively cover the case of Crystal Mason, a Fort Worth woman sentenced to five years in prison for casting a ballot while on supervised release on a tax fraud charge, even though she didn’t know she was not eligible to vote.) Democrats also negotiated the inclusion of a clause allowing election judges to remove poll watchers who violate state law by intimidating voters. And they added language barring poll watchers from obstructing a voter, while also making it a criminal offense for someone to give a voter false information with the intent of preventing them from casting a ballot.

Phelan called the House back to order at 2:42 a.m. on Friday. In the following twenty minutes, the House passed eighteen amendments to SB 7, one of which, authored by Murr, contained 43 substantive changes to the bill.  The amendment was so complex that it took lawyers two and a half hours to draft it. Then, on a mostly partisan vote of 81–64, with only Larson, again, breaking from his party, the House gave the bill tentative approval. The usually testy Cain ended the anticlimactic debate with a whimper rather than the expected bang: “It’s 3 a.m,” he said, resigned. “I close.” The bill was sent back to the Senate later in the day.

One of the negotiators told me Bucy won the day by urging the Republicans, “Let’s not be Georgia; let’s not be Florida.” (Both states recently passed controversial restrictions on voting that were widely denounced as voter suppression.) Despite the backroom success for Democrats, however, Bucy worries that the hard-negotiated changes will be imperiled in a conference committee with the Senate meant to reconcile the two chambers’ versions of the bill. Patrick has played partisan hardball all session, denying Democrats any victories on his package of priority legislation—bills tailored not to the priorities of the majority of Texans but rather to those of Republican primary voters.