Senator 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.

Mrs. Clinton has a nearly insurmountable lead in delegates, which Mr. Sanders’s 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, Mr. Sanders continues to tug Mrs. Clinton to the left.

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

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