Republicans lost their House majority in the 2018 midterm elections, and they can thank their own Obamacare repeal efforts.

Democrats campaigned hard against Republicans for backing legislation last year that would unwind the law’s protections for preexisting conditions, and health care came in as the No. 1 issue for voters, according to exit polls.

Donald Trump stormed to the White House because he was willing to say things and take positions that even his fellow GOP contenders usually wouldn’t touch. But Republican were determined to repeal the Affordable Care Act, making rolling back Barack Obama’s signature legislation their top priority if they ever gained full control of Washington again.

The president went along with the establishment Republican agenda, but repeal proved devastatingly unpopular when the GOP actually tried to pass it, and voters made them, and Trump, pay the price on Election Day.

It seems an issue Trump doesn’t care all that much about and doesn’t even really seem to understand very well broke the GOP’s iron grip on Washington.

Trump’s health care agenda helped end the House Republican majority

Trump endorsed Obamacare repeal as a candidate, just like every other Republican, and when he was sworn in, the top priority for Republicans wasn’t a big tax cut or an ambitious infrastructure plan like Trump had dreamed about. It was trying to pass a bill, any bill, that, in effect, would lead to millions fewer Americans having health insurance. They did manage to get legislation out of the House but fell short in the Senate, wasting most of the first year of Trump’s presidency.

That’s what Trump chose to spend his precious political capital on — an ideologically motivated crusade to cut federal benefits for millions of Americans, a policy platform that almost always leads to electoral disaster.

The Washington Post polled voters in swing House races on Election Day, and 43 percent said health care was one of their most important considerations, including three-fourths of Democratic voters. Democratic voters were actually a little more likely to name health care than Trump himself as their top issue.

That tracks with the polling throughout the 2018 midterms campaign, which found health care was a major focus for voters and they trusted Democrats far more than they trusted Republicans.

Why Trump ended up contradicting Trump on health care

Trump’s dedication to Obamacare repeal never made much sense when you actually listened to what he had to say. Like any other Republican would, he did criticize the law for its insurance regulations and for jacking up premiums. But otherwise, he never articulated much of a philosophy for health care reform, and when he did, he didn’t sound like much of a Republican.

“Everybody’s got to be covered. This is an un-Republican thing for me to say,” Trump said in September 2015, as his presidential campaign was building some momentum, promising to replace Obamacare with something “better.” He repeated the same line in January 2017, shortly before taking the oath of office and undertaking the hard work of actually delivering on that promise: “insurance for everybody.”

But the president never bothered to educate himself on the policy, and the Republican legislation he endorsed was directly counter to his own stated goals: 20 million fewer people would have had health insurance under the various GOP repeal plans. Those pesky regulations that Trump and other Republicans liked to deride actually became pretty popular once Americans understood they protected people with preexisting conditions.

Trump ended up giving his endorsement to the least popular major legislation seen in Congress in three decades. Even he knew it was bad; he memorably called the House GOP health care bill that he had endorsed and was ready to sign “mean.”

By the time voters were heading to the polls, Trump was forced into a baldfaced lie about the Republican commitment to protecting preexisting conditions; the House bill would have rolled back those protections, but three-fourths of Americans want to keep them.

It proved the most potent political attack for Democrats. The party spent more money on ads featuring health care than any other issue. They painted Republicans as heartless for trying to scrap regulations that protected cancer survivors and kids with serious medical conditions from being denied health insurance.

Mean, you might say.

Trump didn’t put a lot of thought into Obamacare repeal. It cost him.

But Trump did it to himself. The president who once admitted “health care is complicated” never appeared to have a firm grasp of the issue.

Granted, granular policy details have never been Trump’s strong suit. But the gap between his relative fluency in tax and trade matters and his total lack of awareness about health care is still stunning. It didn’t help that the issue never created the raw connection between Trump and his most loyal voters that immigration does, and therefore has never received as much of his attention.

As recently as last year, as Vox’s Sarah Kliff noted, Trump seemed to have no idea what health insurance actually cost (hint: a little more than $12 a month), and, to be honest, it sure sounded like he was describing life insurance instead of health insurance. The point is, you couldn’t be sure how well the president understood the bill, and so maybe it should be no surprise that the House GOP bill contradicted Trump’s goals while proving so unpopular with the public.

The Trump administration is still leaving a mark on the ACA, undermining open enrollment and creating loopholes for people to buy insurance plans that don’t comply with the health care law’s rules. But Democrats will try to undo those efforts and carry over health care as a winning issue for them in the 2020 campaign when they try to unseat Trump.

They have reason to be optimistic. On the same election night that delivered a House Democratic majority, voters in three Republican-led states — Idaho, Nebraska, and Utah — also approved ballot initiatives to expand Medicaid under the ACA. The lesson of the 2018 midterms seems to be that even in GOP territory, core parts of Obamacare can play well.

In the meantime, Obamacare is safe from Republican hands — thanks in no small part to Donald Trump.