Gulbadin Naib's team have lost all seven of their matches, leaving them with two games to avoid finishing the tournament without a single point.
"Obviously we played two tough games and today we missed something. Our fielding gave away 30 to 40 extra runs," Naib said.
Rahmat Shah and Gulbadin put on 49 for the first wicket, giving Afghanistan hope of a surprise win.
But Shakib's introduction brought the breakthrough as the spinner weaved his magic.
Match in numbers:
Rahmat carelessly flicked a flatter delivery to Tamim Iqbal at mid-on and departed for 24.
Hashmatullah Shahidi perished when he tried to accelerate, stumped by Mushfiqur Rahim off Mosaddek Hossain for 11.
Bangladesh had victory in their sights after Shakib took two wickets in the space of four balls.
Gulbadin was removed for 47 after driving low to Liton Das at short extra cover before Mohammad Nabi was bowled through the gate for a duck.
Shakib became the first Bangladesh player to take five wickets in the World Cup when he had Najibullah Zadran stumped.
Earlier, Shakib became the leading run scorer in this year's World Cup so far as his side posted a solid score after being put into bat.
Shakib's 51 took him to 476 runs in the tournament, while Mushfiqur top-scored with 83 from 87 balls.
Liton fell for 16 after being fooled into a miscued drive by spinner Mujeeb Ur Rahman, who finished with 3-39.
That brought Shakib to the crease and he upped the tempo with some aggressive hitting that maintained his fine form.
When Shakib, who has two centuries already in the tournament, pulled Naib to the boundary, it moved him above Australia's David Warner's 447 runs.
Tamim and Shakib put on their fourth successive fifty partnership in one-day internationals.
Shakib went on to become only the second player to hit six consecutive 40-plus scores in a World Cup.
Not long after that milestone, Shakib brought up his half-century in 66 balls -- his fifth score of 50 or more in this tournament -- to huge cheers from the Bangladesh fans who made up the majority of the crowd.
Shakib was unable to turn his solid start into another century, but he would contribute more than enough with the ball to seal the victory.
Shakib's 51 laid the foundations for Bangladesh to score 262-7 and made him the leading run-scorer in this year's World Cup