Cardiff: Shakib Al Hasan and Mahmudullah smashed a brilliant century each and stitched together a record 224-run stand as Bangladesh recovered from a top-order collapse to notch up a stunning five-wicket win over New Zealand in their last group match of the Champions Trophy in Cardiff on Friday.

Chasing a target of 266 for a win, Bangladesh were reduced to a precarious 33/4 in the 12th over but Shakib (114) and Mahmudullah (102 not out) turned the match on its head with a remarkable batting display to help their side notch up their first win of the tournament.

Mahmudullah (R) and Shakib Al Hasan celebrate Bangladesh's victory over New Zealand in the Champions Trophy in Cardiff. AFP

The duo batted brilliantly for 34.5 overs for the fifth wicket and orchestrated a sensational comeback for Bangladesh after a devastating three-over three-wicket opening spell from Tim Southee (3/45) had rocked their run chase.

Bangladesh eventually chased down the target with 16 balls to spare, reaching 268/5, to fashion one of the most memorable victories in their ODI history.

The 224-run stand between Shakib and Mahmudullah was the highest for Bangladesh for any wicket in ODIs, eclipsing the earlier 178 between Tamim Iqbal and Mushfiqur Rahim against Pakistan in 2015.

Shakib, who hit his seventh ton in his 176th match, struck 11 fours and a six from 115 balls while Mahmudullah, who got his third ton in his 144th game, had eight fours and two sixes from 107 deliveries in his unbeaten knock.

With the loss, New Zealand are out of the tournament, after finishing at the bottom of Group A with just one point which they got after their match against Australia was washed out. They had lost to England by 87 runs.

Despite the win, Bangladesh, who now have three points from three matches, are still uncertain of a semi-final berth and they will have to wait the outcome of the Group A match between England and Australia in Birmingham on Saturday.

If Australia beat England, Bangladesh will not qualify for the semi-finals. In that case, both England and Australia will advance to the last four.

Bangladesh will qualify for the semi-finals if England beat Australia.

Bangladesh's run chase began in a dramatic fashion with their in-form batsman Tamim being out for a duck in the second ball of innings with no run on board.

Tamim, who had hit a ton and a 95 in the two earlier matches, played the wrong line off a Southee delivery and was adjudged LBW.

Southee returned to dismiss Sabbir Rahman (8) in his next over as the batsman nicked to wicketkeeper Luke Ronchi as the delivery seamed away slightly to reduce Bangladesh to 10/2 in the third over.

Bangladesh's run chase was then thrown into disarray in the fifth over when Southee removed Soumya Sarkar (3) in the fifth over and his third, this time also winning an LBW decision as the ball skid back in after landing on a good length.

The top-order collapse meant that Bangladesh went into a shell and runs were trickling only in singles for a lot of overs. New Zealand were not to be denied their fourth wicket as Adam Milne dismissed Mushfiqur Rahim (14) in the 12th over as the fast delivery crashed through the batsman's gate to send the middle stump cartwheeling.

The Kiwis were in command but Shakib and Mahmadullah slowly and steadily turned the tables in Bangladesh's favour. The duo grafted for runs initially ensuring that no further damage was done before they opened up to hit some exquisite shots to run away with the match.

Earlier, Mosaddek Hossain (3/13) triggered a New Zealand batting collapse towards the end with three scalps as Bangladesh restricted the Kiwis to 265/8.

The 21-year-old batting all-rounder stole the show with his off-spin as he grabbed three wickets in the space of 12 balls to turn the match on its head.

Mosaddek took two wickets - that of Niel Broom (36) and Corey Anderson (0) - in the 44th over and then had another one in the 46th over in the form of James Neesham (23) to stop the Kiwis in their tracks.

Bangladesh captain Mashrafe Mortaza's decision to introduce Mosaddek in 42nd over turned out to a masterstroke as New Zealand could add just 62 runs from the final 10 overs.

Electing to bat, New Zealand were nicely set up for a challenging total by captain Kane Williamson (57 off 69 balls) and Ross Taylor (63 off 82 balls) with solid half-centuries but their good work were undone later as wickets tumbled in a heap in the slog overs.

The Kiwis were 201/3 in the 39th over and 203/4 at the end of the 40th over and they looked set to adding maximum runs in the final 10 overs but that never happened.

New Zealand began at a brisk pace with Martin Guptill (33) and Ronchi (16) finding the boundaries. Taskin Ahmed gave the first breakthrough for Bangladesh in the eighth over by dismissing Ronchi who mistimed his shot to be holed out to Mustafizur Rahman at mid on.

Guptill was the next batsman to go in the 13th over as he was beaten by a Rubel Hossain delivery to be out LBW.

With two wickets gone, New Zealand sought to consolidate their innings with captain Williamson and Taylor taking charge. The duo complied runs mostly through singles and doubles with occasional fours.

Williamson brought up his fifty in the 15th over with a single off Rubel and New Zealand were 134/2 at the halfway mark. He fell in a horrible mix-up in the 30th over as he was sent back by Taylor after starting for a single.

Williamson was short of his crease as the bowler Shakib ran him out. His 57 had five boundaries.

After Williamson's departure, Taylor was going strong but he had a soft dismissal in the 39th over as he mistimed a shot to Mustafizur. His 63 had six boundaries in it.

The match was delayed for one hour due to rain but there was no reduction in the overs. Both the teams went into the match without even knowing whether a win will guarantee them a place in the semi-finals.