Updated at 9:04 p.m. ET

In a gamble that looks poised to shape the 2018 midterm landscape, the vast majority of House Republicans in districts that backed Democrats in any of the most recent presidential elections voted to repeal the Affordable Care Act in Thursday’s nail-biting tally. That decision will elevate almost all of them on the target list for Democrats aching to recapture the House majority next year.

Most immediately, 14 of the 23 Republicans holding seats that voted for Hillary Clinton last November ended up supporting the legislation, which would replace former President Barack Obama’s law with a GOP alternative. All seven of the California Republicans in districts Clinton carried voted for the bill; elsewhere, the Clinton-district Republicans split more closely, with nine opposing the legislation and seven supporting it.

Looking at a broader list of legislators in competitive seats, the highly controversial plan drew support from fully 46 of the 61 House Republicans in districts that voted either for Clinton in 2016 or for Obama in his 2012 or 2008 elections, according to district results provided by TargetSmart, a Democratic voter-targeting firm. Only 15 of the Republicans from those districts voted “no.” Of the 20 total GOP representatives who voted against the plan, five represent more reliably Republican seats that did not back Democrats in any of the previous three presidential elections.

Tom Davis, a former Virginia congressman and chair of the National Republican Congressional Committee, argued that while the alternative to the ACA faces resistance in polls, opposing it would have been a greater risk for House Republicans than supporting it. That is because he believes failure would have depressed the Republican base. Like other GOP strategists, Davis views that as a greater risk than alienating swing voters, who polls have shown dislike both the original GOP bill that failed earlier this spring and the changes that were made to revive it.

“I think they have to pass it, because a dispirited base going into the midterms [is dangerous],” he said. “The Democratic base is going to be spiked no matter what. So they have to do this.”

Davis, now president of federal affairs for the consulting company Deloitte said he believes Democrats face a demographic impasse on the legislation. On the one hand, in the white-collar, “higher-income suburban districts” where Trump is unpopular—and where Republicans appear most vulnerable for 2018—“you’re not taking their stuff away, they are not the people who are getting punished,” he argued. On the other, the GOP advantage, largely on cultural issues and Trump-like nationalism, is too entrenched to overturn in the blue-collar and rural districts likely to face greater material consequences from the repeal, he said.

But Charlie Kelly, executive director of House Majority PAC, a political-action committee that supports Democratic House candidates, said the health-care legislation’s tangible economic impact had the potential to cut through the GOP’s cultural advantage in the blue-collar and nonurban districts that have been trending toward Republicans since 2010.

“This is very much a kitchen-table thing,” Kelly said. “It’s something that is very easy to understand, and from a connection standpoint it’s not hard for people to see they just took away 24 million Americans’ health care. You can’t explain that. And all these things with charging seniors and folks over 50 more [for premiums], that just doesn’t make sense. Who is on your side is a fundamental question.” In economically struggling blue-collar communities, Kelly added, “They took a chance on Trump and this is a shock.”

Polls found the initial Republican legislation faced preponderant public opposition: A late March Quinnipiac University survey found that fewer than one in five adults supported it, while 56 percent opposed it. Opposition spiked past 60 percent among older adults ages 50 to 64, a largely white and Republican-leaning constituency. An ABC/Washington Post survey likewise found that 70 percent of all adults—and three-fourths of those 50 and older—opposed ending the ACA’s nationwide guarantee of affordable coverage for people with preexisting conditions. The House legislation allows states to opt out of those protections.

Despite the warning signs in public opinion, the bill drew broad support from Republicans in every category of electorally conflicted district. Eight House Republicans hold seats that voted Democratic in each of the past three presidential elections, per TargetSmart’s analysis. They split evenly on the health-care vote, with four opposing and four supporting the bill. The supporters were Jeff Denham and David Valadao of California, Carlos Curbelo of Florida, and Erik Paulsen of Minnesota. Clinton carried the Valadao and Curbelo districts by more than 15 percentage points, the Paulsen district by 9, and the Denham district more narrowly by three. (The opponents were: Mike Coffman of Colorado, John Katko of New York, David Reichert of Washington, and Ileana Ros-Lehtinen of Florida.)

Another 18 Republicans hold seats that voted Democratic in two of the past three presidential races. Thirteen of those 18 voted for the bill. Virginia’s Barbara Comstock, Texas’s Will Hurd, New Jersey’s Frank LoBiondo, and two Pennsylvania representatives from suburban Philadelphia—Ryan Costello and Pat Meehan—voted against the bill.

Of the final 35 Republicans in seats that voted Democratic just once in the past three presidential elections, 29 voted for the legislation. The “nays” included two additional Pennsylvanians—Charlie Dent and Brian Fitzpatrick—along with Leonard Lance of New Jersey, Michael Turner of Ohio, and Jaime Herrera Beutler of Washington.

Another gauge of political vulnerability points to the same message: Of the 76 House Republicans in districts where Trump lost ground relative to Mitt Romney in 2012, all but nine voted for the bill.

Since the GOP regained the House majority in 1995, the party leadership has usually muscled through tough legislation by moving bills to the right to placate conservatives and betting that enough moderates in more competitive districts buckle and support them in the end. House leaders placed a similar wager by revising this Obamacare-replacement legislation to meet the demands of the House Freedom Caucus. The overwhelming vote for the final bill among Republican members, in seats that have voted Democratic for president at least once since 2008 or where Trump lost ground relative to 2012, points toward the unmistakable conclusion that their bet paid off.

In a measure of the anxiety the legislation has stirred among older Americans, 16 of the 20 Republicans who opposed the legislation represent districts where the median age exceeds the national average. But overall, Republicans representing older districts tilted heavily toward the bill. That’s despite the Congressional Budget Office’s conclusion that the original version would produce big increases in premiums for older, working-age adults, and despite intense opposition from AARP Advocates, the lobbying group for older Americans.

In all, 125 of the 141 Republicans representing older districts supported the bill, according to Atlantic calculations. Fully 92 of the 96 Republicans in seats younger than the national average backed it, a considerably higher percentage.

The widespread support from Republicans with older constituencies, some Democratic strategists believe, could provide them an opening to challenge members in gray-tinted districts that had not been high on the party’s radar, including places where Trump made gains compared with Mitt Romney in 2012. Seats in that category might include those held by Republicans John Faso in New York, Brian Mast in Florida, and Bruce Poliquin in Maine—each of whom voted for the bill.

One of the most striking patterns in the vote was the support for the legislation among all seven California Republicans in districts that Clinton won last year. Their unanimity—contrasted with the roughly even division among Clinton-district Republicans outside of California—was especially noteworthy because nearly four million people in California have gained coverage under the ACA. That’s more than double the number in any other state, according to Urban Institute calculations. Since 2010, the state’s uninsurance rate has fallen by more than half.

Bill Carrick, a longtime Los Angeles-based Democratic strategist, called the vote a “huge risk” for the Clinton-district California Republicans—a list that includes Denham, Valadao, Dana Rohrabacher, Mimi Walters, Ed Royce, Darrell Issa, and Steve Knight. The risk is magnified, Carrick said, because in several cases population change has rendered the districts more diverse, and less reliably Republican, than when they were drawn after the 2010 Census.

“You have the political changes in the districts, and nobody has seized on it,” Carrick said. “This puts a harsh light on it. … Hillary wins the district [in 2016] and several of them had closer races than they had in years. So now the voters start asking, ‘What kind of Republican are they?’ And this is a bad answer.”