New Zealand would have joined England in the knockouts with a win in their final Super Eights match and they scored 159-6 after opting to bat.
England lost wickets early and looked like they would be squeezed out at 117-6, needing 43 from the last three overs.
But Ahmed and Jacks took 22 off the 18th over from Glenn Phillips to turn the match on its head.
Ahmed blasted 19 off seven balls in his first T20 World Cup match.
Jacks made an unbeaten 32 off 18 as the pair saw England to 161-6 with three balls to spare.
Jacks, who also took 2-23 to be England's leading bowler, was named player of the match for an incredible fourth time in seven T20 World Cup outings this campaign.
"I reckon this is the best," said Jacks of his growing collection of player of the match awards.
"I'm absolutely buzzing with that, to be not out at the end in a tight finish.
"When I went out there, it was on a bit of a knife-edge, and I'm over the moon."
New Zealand captain Mitchell Santner paid tribute to Ahmed and Jacks.
"Rehan showed his class with the bat in the last couple of years and is obviously a very good player of spin," said Santner.
"So he wasn't really fazed on that wicket. The way Willy J and Rehan put those finishing touches was a good bit of batting."
Mumbai semi-final for England
England will move on to a semi-final in Mumbai on Thursday against either India or the West Indies, who clash on Sunday to decide the last semi-final berth.
"We're not bothered (who we play)," said England captain Harry Brook, whose side played two group matches in Mumbai, beating Nepal but losing to the West Indies.
"Whoever we're facing, they're going to be a tough opponent anyway. We've already played against the West Indies, so a little bit of experience there.
"It's nice to go back to a ground that we've already played on as well."
New Zealand now have to sweat on the outcome of Saturday's clash between Sri Lanka and Pakistan in Kandy which will decide the second semi-finalist from Super Eights Group 2.
Pakistan have an inferior run rate to New Zealand so will need to win by 65 runs or inside 13 overs, if chasing, to deny the Kiwis.
"We'll probably be watching the game tomorrow," said Santner, whose side remain favourites to go through.
England used five spinners to bowl 16 of the 20 overs on a turning track. The 2010 and 2022 champions had never bowled so many overs of spin before in a T20 international.
Adil Rashid picked up 2-28 and is now England's leading wicket-taker in the tournament with 11.
Rashid was complemented by fellow wrist spinner Ahmed, who was called up in place of Jamie Overton, and took a wicket with his first ball before finishing with 2-28 from three overs.
Glenn Phillips top scored with 39 off 28 including four fours and a six while opener Tim Seifert scored 35.
Liam Dawson (1-32) and Jacob Bethell (0-13) were the other spinners employed by England.
