Bangladesh produced another Cardiff victory every inch as remarkable as the 2005 triumph over Australia to keep their Champions Trophy hopes alive and eliminate New Zealand.

Needing 266 to beat the Black Caps and remain in with a chance of a semi-final spot, Bangladesh's reply was close to ruins after being reduced to 33 for four in the 12th over.

But Shakib Al Hasan (114) and Mahmudullah (102 not out) combined to produce the greatest partnership in Bangladesh limited-overs history.

It eclipsed the 178 shared by Tamim Iqbal and Mushfiqur Rahim against Pakistan in 2015, and was the second highest partnership in Champions Trophy history.

A dozen years after their first win over world champions Australia came at Cardiff, the pair put on 224 in 219 balls as Bangladesh turned potential embarrassment into a five-wicket win with 16 balls to spare.

The scenario of this penultimate Group A match was straightforward.

The winner would have to wait on the outcome of Saturday's clash between England and Australia to determine whether a semi-final spot had been secured.

The loser would head for home with only one point from three games, and that appeared Bangladesh's fate after Tim Southee had ripped through the top of their batting order.

Shakib Al Hasan reached a century for Bangladesh (Reuters)

New Zealand had suffered a familiar batting collapse on their way to posting 265 for eight from their 50 overs, but Trent Boult had promised before the game that the Kiwi bowlers would adopt an aggressive approach.

Boult and new-ball partner Southee backed up those words as Tamim, in destructive form at this tournament with scores of 128 and 95 against England and Australia, fell lbw to the second ball of the innings.

Tamim had no answer to a delivery which straightened on him and was shown to be hitting the stumps after Bangladesh had asked for a review.

Southee then detected the edge of Sabbir Rahman's bat to claim his 159th victim in ODI cricket and take him past Sir Richard Hadlee and up to sixth on New Zealand's all-time list of leading wicket-takers.

Mahmudullah in action for Bangladesh (Reuters)

But he was not finished there as Soumya Sarkar was beaten by one which jagged back and struck in front to leave Bangladesh 12 for three.

Boult should have got in on the act when Ross Taylor, injuring himself in the process, spilled Mushfiqur's hard edge to slip.

Mushfiqur was soon castled by Adam Milne for 14 and the noisy Bangladesh support had fallen silent.

But they rediscovered their voices as Shakib and Mahmudullah set off on the most unlikely of run chases.

The pair played beautifully in finding the gaps, running hard and taking on the boundaries when the big shots were there to be played.

Even arm cramps could not disturb Shakib, who called for the physio twice but continued to complete his hundred with a first six of the innings.

It was a disappointing afternoon for the Black Caps (Reuters)

Mahmudullah also reached three figures as Bangladesh closed in on victory and New Zealand were ragged by the end, with 17 wides adding to their misery.

Earlier, New Zealand had been well-poised at 152 for two with Kane Williamson and Taylor supplying further mid-innings stability after partnerships of 95 and 99 against England and Australia.

But New Zealand have repeatedly folded after the departure of skipper Williamson, losing seven wickets for 37 runs against Australia and eight for 65 in defeat to England.

This time, after Williamson had made his lowest score of the tournament - 57 from 69 balls - New Zealand lost six wickets for 103 as Mossadek Hossain (three for 13) and Taskin Ahmed (two for 43) led a spirited Bangladesh bowling unit.

Taylor top-scored with 63 from 82 balls, but it is Bangladesh who now hope England can beat Australia at Edgbaston to secure their own progress to the last four.