Sen. Bernie Sanders of Vermont captured the West Virginia primary on Tuesday, forcing Hillary Clinton to continue a costly and distracting two-front battle: to lock down the Democratic nomination and to take on Donald J. Trump in the general election.

Clinton has a nearly insurmountable lead in delegates, which Sanders’ victory, one week after he won Indiana, did little to narrow. But by staying in the race, as he has vowed to do until the Democratic convention in Philadelphia in July, Sanders continues to tug Clinton to the left.

This week, after long resisting Sanders’ call for a single-payer health care system, Clinton embraced allowing people as young as 50 to buy into Medicare.

In Oregon, which votes next week, Sanders appealed to unpledged superdelegates, who can cast votes as they please at the convention, to rally behind him as the stronger opponent to Trump.

“If you look over the last month or six weeks, at every national poll, Bernie Sanders defeats Donald Trump by big numbers,” he said.

With Trump aggressively attacking Clinton as he focuses on the general election, Clinton’s potential vulnerability was exposed in her defeats in West Virginia and Indiana, states with many white, working-class voters.

Once a core Democratic constituency, whites in Appalachia without a college education have deserted the party over cultural issues like guns and President Barack Obama’s environmental policies, which have hurt the coal mining industry.

Clinton tried to repair relations in the last week, less because of her contest with Sanders than to mend fences for the November election.

She campaigned hard along the Ohio River, knowing that she must stanch the defection of working-class voters, especially white men, to Trump in two crucial states, Ohio and Pennsylvania.

Her campaign, which has not bought television ads since her sweep of four Eastern states on April 26 and hoped to conserve money for the general election, is going back on the air in Kentucky before its primary next week.

Clinton’s vulnerability in Ohio and Pennsylvania was highlighted

by polls released Tuesday by Quinnipiac University, which showed her running close with Trump in the two states but losing ground because of a wide gender gap. In Ohio, which has voted with the winning candidate in the last 10 presidential elections, she was ahead of Trump by 7 percentage points among women, but behind by 15 points among men.

In Pennsylvania, which Trump aims to win as part of a Rust Belt strategy, Clinton was ahead among women by 19 points, but losing to Trump among men by an equal 19 points.

Trump, who became the apparent Republican nominee last week with a landslide victory in Indiana, added icing to the cake on Tuesday by taking West Virginia and Nebraska. (Democrats voted in Nebraska on March 5.)

Even before the withdrawal of his last Republican rivals, Sen. Ted Cruz of Texas and Gov. John Kasich of Ohio, Trump was far and away the leader in West Virginia polls. At a rally in the state last week, he promised to bring back coal mining jobs, without giving any details.

The decline of coal in Appalachia is a result of increased mechanization of mining, the conversion of power plants to cheaper natural gas, and environmental regulations. The industry and its political allies play down the first two and blame the White House for a “war on coal.”

Trump, who has repeatedly called climate change a “hoax,” opposes Obama’s plan to reduce carbon emissions from power plants. Clinton and Sanders both propose more rapid transitions to cleaner energy, partly to create new jobs.

Clinton was haunted throughout her visits to West Virginia and Kentucky last week by a comment she made in March that her climate change policies would “put a lot of coal miners and coal companies out of business.” She made the remark in the context of pledging money to coal communities, but the sound bite trailed her, and she found herself repeatedly on the defensive.

Sanders’ victory was less about policy differences with Clinton (his environmental plans would phase out coal more rapidly) than about the state’s demographics. He beat Clinton in a largely white, rural state, as he has throughout the primaries.

Eight years ago, when Clinton defeated Obama in West Virginia’s primary, 1 in 5 voters said in exit polls that race had been a factor.