Afghanistan beat Scotland by one wicket with three balls to spare to claim their first World Cup win.

Chasing 211 in Dunedin, Afghanistan were reduced to 97-7 but Samiullah Shenwari's 96 gave them hope.

He was caught on the boundary with 19 still required, but last man Shapoor Zadran hit the third ball of the final over for four to seal victory.

Scotland had earlier rallied from 144-8 to make 210, but their search for a first World Cup win goes on.

They have now lost all 11 matches they have played in three World Cups, surpassing the Netherlands' previous record of 10 successive defeats from debut.

Ex-England spinner Vic Marks on Test Match Special

"That was an amazing game of cricket. Not the highest quality but as dramatic as I have seen in a long time. Afghanistan, against all the odds, have triumphed. Scotland are disconsolate."

It was the second thrilling match between two non-Test playing sides in as many days following Ireland's two-wicket win over the UAE on Wednesday.

Scotland will reflect on a missed opportunity to record their first World Cup win but, in a match of regularly fluctuating fortunes, both teams surrendered positions of strength.

Ultimately, it was the efforts of Shenwari and the nerve of last-wicket pair Shapoor and Hamid Hassan that earned a historic win for Afghanistan, a nation that was still competing in the bottom tier of the International Cricket Council's world league in 2008.

After the Afghans suffered a middle-order collapse of five wickets for 12 runs, Shenwari painstakingly rebuilt, before opening his shoulders to make an unlikely run-chase seem possible.

How's stat?!

No team winning a World Cup match batting second has had a collapse where they lost five wickets for 12 or fewer runs before Afghanistan here (85-2 to 97-7).The worst previous five-wicket collapse by a team batting second and going on to win a World Cup game was 14 by Bangladesh v England at Chittagong in 2011. They lost 5-14 (155-3 to 169-8) before reaching 227 to win.

With 38 required from the final four overs, Shenwari three times heaved Majid Haq for six over the leg side, only to be caught on the boundary looking for the fourth that would have taken him to a century.

That left Afghanistan still 19 short, but Shapoor and Hassan inched nearer and, when Richie Berrington's final ball of the 49th over was clipped for four, only five were needed from Iain Wardlaw's six deliveries.

Shapoor could have been run out had Matt Machan's throw hit the stumps but, from the next delivery, the left-hander clipped to the square-leg boundary to seal victory.

It was a cruel defeat for Scotland, who will rue missed chances, not least Haq's drop of Shenwari at slip when the right-hander was on 20.

Haq, though, had already played his part in ensuring that Scotland were not on the end of a heavy defeat, sharing a Scottish record ninth-wicket stand of 62 with Alasdair Evans.

The Scotland top order had earlier been run through by the impressive Afghan pace trio of Shapoor, Hassan and Dawlat Zadran, who showed consistency of length to exploit the assistance offered in the pitch.

Scotland played a part in their own downfall, Machan's horrible swipe at Mohammad Nabi beginning a regular fall of wickets that left them in a seemingly hopeless position.

However, that was to discount Haq and Evans, who rebuilt first through patient accumulation, then accelerated to take Scotland to their highest World Cup total.

It looked like being enough when Evans and Berrington got to work on the Afgan middle-order, but there was to be another bout of late resistance.

Shenwari found batting support from all three of Afghanistan's pacers and, ultimately, it was Shapoor who had the final say.

The victory for Afghanistan, England's final group opponents, keeps their hopes of reaching the quarter-finals alive, while Scotland, who next play Bangladesh on 4 March, are on the brink of elimination.