Media playback is unsupported on your device Media caption Bernie Sanders: "We must defeat Donald Trump"

Bernie Sanders has won the West Virginia primary in the Democratic race for the presidential nomination, US media project.

The Vermont senator still trails Hillary Clinton in the overall contest for delegates but this win keeps his slim hopes alive.

"We are going to fight for every last vote," he said in a victory speech that also attacked Republican Donald Trump.

Mr Trump was declared the winner in West Virginia and in Nebraska.

His last remaining rivals dropped out last week but remained on the ballot.

But Mr Trump faces a huge task in trying to get the Republican party behind him, as doubts persist about his substance and style.

House Speaker Paul Ryan, the party's highest-ranking elected official, has said he is unable to endorse the New York businessman because he lacks conservative principles.

Anthony Zurcher, BBC News, Washington

With victories in Indiana and now West Virginia, Bernie Sanders has started another winning streak against Hillary Clinton. Like his five-state run in April, however, it will do little to slow her steady march to the Democratic nomination.

Exit polls show the West Virginia vote was particularly quirky. Almost 40% of Democratic voters there said they wanted a president less liberal than Barack Obama - and that group favoured avowed socialist Sanders by more than a two-to-one margin.

Mr Sanders also overwhelmingly carried the 27% who want a president more liberal than Mr Obama.

Such a result makes sense if some of Sanders's support is, in fact, an anyone-but-Clinton vote.

At this point the Vermont senator will likely take help wherever he can get it. He should be competitive in the next four contests, but could hit a wall in the June mega-prize, California. Its diverse electorate favours Mrs Clinton, and anything but an unprecedented Sanders win there would seal his fate.

Until then, however, Mr Sanders will continue to be a constant and unpleasant reminder to Mrs Clinton that there are Democratic voters still unwilling to fully get on board her campaign.

Your browser does not support the iframe HTML tag. Try viewing this in a modern browser like Chrome, Safari, Firefox or Internet Explorer 9 or later.

With Mr Trump now the Republican presumptive nominee, it was the Democratic race that provided the focus for Tuesday's primaries.

Mr Sanders's victory in West Virginia, where Mrs Clinton convincingly beat Barack Obama in 2008, will prolong the Democratic contest.

In a speech delivered in Salem, Oregon, which holds its primary next week, Mr Sanders vowed to fight on.

"We have now won primaries and caucuses in 19 states and let me be as clear as I can be - we are in this campaign to win the Democratic nomination."

Image copyright Reuters Image caption All set for Trump and Clinton? Sanders says not so fast

He pointed to polls as evidence that he remained the best Democratic candidate to beat Donald Trump.

And he turned his fire on the billionaire property developer for insulting women, Hispanics, Muslims, African Americans and veterans.

Despite his differences with the former secretary of state Mrs Clinton, Mr Sanders said, they had one common goal - defeating Mr Trump.

Exit polls in West Virginia suggested one-third of those who voted for Mr Sanders would switch to Mr Trump in a general election between the two men.

Staying power: US papers on Sanders

The New York Times said Mrs Clinton had a "nearly insurmountable lead in delegates… but by staying in the race… Mr Sanders continues to tug Mrs Clinton to the left".

The Washington Post said that the more delegates Mr Sanders can collect over the coming months, "the more leverage" his aides say he will have "in shaping the party's platform". In particular, "he would like to push Clinton to adopt his position on issues including universal health care and raising the minimum wage."

West Virginia's local newspaper, the Charleston Gazette, says Mr Sanders won the state because his "core message about the economy resonated" with the voters, who largely voted for Mrs Clinton in 2008. But, the paper notes, "West Virginians have been drawn to Mr Trump from the beginning of his campaign, largely because of his business experience and pledges to bring back jobs, particularly coal jobs."

More on the campaign

Media playback is unsupported on your device Media caption The story of his campaign - in controversial quotes

28 things that Donald Trump believes

Are Trump and Sanders right about trade?

Full US election coverage from the BBC