Stokes then walked in to bat with England tottering on 46 for four in the second innings and propped up his team with a fighting 85.
At stumps, England had reached 228 for eight for an overall lead of 273. Chris Woakes (11) and Stuart Broad were unbeaten at the crease.
Scoring runs was becoming increasingly difficult on the spinning track at the Zahur Ahmed Chowdhury Stadium and England suffered early losses in their second innings.
The touring side were in dire straits at 62 for five but Stokes added 127 for the sixth wicket with Jonny Bairstow (47), hitting six fours and three sixes before he fell lbw to Shakib Al Hasan.
Left-arm spinner Shakib (5-79) picked up his 15th five-wicket haul in tests, making amends for playing a rash shot to get out in the morning.
Shakib (31) also claimed the wickets of Ben Duckett, Joe Root, Moeen Ali and Adil Rashid.
Earlier, the hosts looked as if they would get their noses in front when they resumed on 221 for five but England needed just over an hour to bundle them out.
Shakib danced out to Moeen's off-spin on the second delivery of the day but was nowhere near the ball and was stumped by yards.
Stokes swung the ball, adding the wickets of debutant Sabbir Rahman, Mehedi and Kamrul Islam to his tally.
Moeen finished with 3-75 as Bangladesh lost their last six wickets for 27 runs.
(Reporting by Sudipto Ganguly in Mumbai; editing by Ed Osmond)
