Electing to bat at the Manuka Oval, Bangladesh were in trouble at 119 for four before Shakib (63) and Rahim (71) stitched a 114-run fifth wicket partnership to take the Tigers to some respectability.
Bangladesh though were set for a bigger score but the wickets of Shakib and Rahim not only stirred a collapse but gave the Afghan bowlers a new lease of life as Mashrafe Mortaza and company lost 5 wickets for just 34 runs in the last five overs of the innings.
Earlier an inspired spell of bowling from Mirwais Ashraf (2-32) saw Afghanistan push Bangladesh on the backfoot as the medium-pacer sent openers Anamul Haque and (29) Tamim Iqbal (19) back in the hut early.
Soumya Sarkar (28) and Mahmudullah (23) then tried to take stock of the situation only to see Shapoor Zadran (2-20) strike back with another set of wickets.
The tall new-ball bowler trapped Sarkar lbw for 28 and soon got Mahmudullah caught behind for 23 as the Afghan fans celebrated like crazy.
Shakib and Rahim though thwarted all Afghan plans as the duo mixed the right dose of caution and aggression to bring some sanity to the innings.
Shakib, registering his 27th ODI fifty, hit 6 fours and a six in his 51-ball stay while Rahim, notching up his 19th ODI half-century, also hit 6 fours and a six during his 56-ball blitz.
The duo also managed to eke out 48 runs from the powerplay overs between 36-40.
But the Afghans never lost focus as the Mohammad Nabi-led side came back in the 45th over to see pace spearhead Hamid Hassan (2-61) clean up dangerman Shakib and bowl out Sabbir Rahman (3) in his very next over.
Mortaza struck a 9-ball 14 but medium-pacer Aftab Alam (2-55) clean bowled him. The tail couldn’t survive the disciplined bowling as the No.11 Taskin Ahmed (1) fell on the last delivery of the innings.
Bangladesh – Mashrafe Mortaza (captain), Tamim Iqbal, Anamul Haque, Mominul Haque, Mushfiqur Rahim, Sabbir Rahman, Shakib Al Hasan, Mahmudullah, Soumya Sarkar, Taskin Ahmed, Rubel Hossain
Afghanistan – Mohammad Nabi (captain), Afsar Zazai, Javed Ahmadi, Nawroz Mangal, Asghar Stanikzai, Samiullah Shenwari, Najibullah Zadran, Mirwais Ashraf, Aftab Alam, Shapoor Zadran, Hamid Hassan (Reporting by Nick Mulvenney in Sydney; Editing by John O’Brien)