The co-hosts looked to be probably heading out of the competition when they collapsed to 169-8 chasing 225 to win on a tricky wicket.
But Shafiul decided attack was the best way ahead and he blasted 24 in as many balls to see his team over the line for the unlikeliest of wins as the home crowd went wild.
Earlier, Jonathan Trott top-scored for England with 67 backed up by Eoin Morgan (63) to help their side recover from a poor start in the Group B clash.
The result was an amazing turnaround for the home side who were skittled for just 58 against West Indies a week ago in Dhaka before losing by nine wickets.
Mahmudullah (21) and Shafiul added 58 runs in their unbroken ninth wicket to take their team to victory with an over left.
Bangladesh had been apparently cruising towards victory thanks to solid innings from Imrul Kayes (60) and Tamim Iqbal (38).
But they suddenly lost momentum with the victory in sight as five wickets tumbled for 14 runs before Shafiul and Mahmudullah rescued their country.
England now need to win their final match against the West Indies (March 17) to be sure of a quarter-final place while Bangladesh next face Netherlands on Monday and then South Africa on March 19. Wins would take them through.
Teams:
Bangladesh - Tamim Iqbal, Imrul Kayes, Junaid Siddique, Raqibul Hasan, Shakib Al Hasan (capt), Mushfiqur Rahim (wk), Mohammed Mahmudullah, Naeem Islam, Abdur Razzak, Shafiul Islam, Rubel Hossain
England – Andrew Strauss (capt), Matt Prior (wk), Jonathan Trott, Ian Bell, Eoin Morgan, Ravi Bopara, Paul Collingwood, Tim Bresnan, Graeme Swann, James Anderson, Ajmal Shahzad
Scoreboard:
Full scoreboard of the World Cup Group B match between Bangladesh and England at the Zahur Ahmed Chowdhury stadium on Friday:
England:
A. Strauss c Siddique b Naeem 18
M. Prior st Rahim b Razzak 15
J. Trott c Siddique b Shakib 67
I. Bell c Naeem b Mahmudullah 5
E. Morgan c Kayes b Naeem 63
R. Bopara c Naeem b Razzak 16
G. Swann c and b Shakib 12
P. Collingwood run out 14
T. Bresnan c Shafiul b Rubel 2
Ajmal Shahzad b Shafiul 1
J. Anderson not out 2
Extras: (lb2, w8) 10
Total (all out, 49.4 overs) 225
Fall of wickets: 1-32 (Prior), 2-39 (Strauss), 3-53 (Bell), 4-162 (Morgan), 5-182 (Trott), 6-195 (Bopara), 7-209 (Swann), 8-215 (Bresnan), 9-217 (Shahzad), 10-225 (Collingwood).
Bowling: Shafiul 8-0-43-1 (w3), Rubel 8.4-0-40-1 (w2), Naeem 8-0-29-2, Razzak 10-2-32-2 (w3), Mahmudullah 5-0-30-1, Shakib 10-0-49-2
Bangladesh:
Tamim Iqbal b Bresnan 38
Imrul Kayes run out 60
Junaid Siddique run out 12
Raqibul Hasan b Shahzad 0
Shakib Al Hasan b Swann 32
Mushfiqur Rahim c Prior b Shahzad 6
Mohammad Mahmudullah not out 21
Naeem Islam b Shahzad 0
Abdur Razzak c Bresnan b Swann 1
Shafiul Islam not out 24
Extras: (b1, lb9, w23) 33
Total (for eight wickets, 49 overs) 227
Did not bat: Rubel Hossain
Fall of wickets: 1-52 (Tamim), 2-70 (Siddique), 3-73 (Raqibul), 4-155 (Kayes), 5-162 (Shakib), 6-166 (Rahim), 7-166 (Naeem), 8-169 (Razzak).
Bowling: Anderson 9-0-54-0 (w7), Shahzad 10-0-43-3 (w9), Bresnan 10-1-35-1 (w1), Swann 10-1-42-2 (w2), Bopara 3-0-19-0 (w4), Collingwood 7-0-24-0
Result: Bangladesh won by two wickets
Toss: Bangladesh
Umpires: Daryl Harper (AUS) and Rod Tucker (AUS)
TV umpire: Aleem Dar (PAK)
Match referee: Jeff Crowe (NZL)