The Potters, who had been defeated in their last four Premier League fixtures, took a deserved first-half lead through Robert Huth and looked home and dry when Ricardo Fuller made it 2-0 in the 71st minute.
But Blues, as they had done on Saturday against West Ham, swiftly erased the deficit thanks to Keith Fahey and Cameron Jerome, but Whitehead netted five minutes from time to win the contest.
The much-needed victory lifted Stoke above Birmingham in the table to 15th, with the Blues sliding down to 17th.
It had appeared the three points would be secured in a comfortable manner by the mid-point of the match after an opening period the hosts had dominated.
Stoke were soon on the front foot as their wingers began to impose themselves, Matthew Etherington aiming a cross at Kenwyne Jones' head and the ball falling to Jermaine Pennant, who produced an even better delivery that the Trinidad and Tobago striker nodded wide.
Pennant then floated another delightful ball into the danger zone from the right but Ben Foster was able to claim it.
Potters fans protested for a penalty moments later when Foster collided with Danny Higginbotham as the goalkeeper rushed out to push the ball away, but referee Mark Clattenburg waved play on and Fuller saw his attempt deflect off target.
The home side continued to send crosses into the Birmingham box, with Jones heading wide again and Foster just managing to keep Huth at bay.
A defensive mix-up for the Blues saw Fuller slipped in, but Foster was alert once more and came out to take the ball off the Jamaican's toe.
The England stopper looked less assured soon after as he flapped near his goal-line at a Rory Delap long throw, although he did appear to have Huth leaning against him.
Whitehead collected a knock-down in the 37th minute and attempted to unleash a shot that hit a defender and went for a throw.
Delap hurled it into the box again but this time Foster confidently fisted it away.
Another Delap throw led to a corner three minutes before the break which Jones rose to meet powerfully, Foster tipping the header over the bar.
But two minutes later Stoke's pressure finally paid off as they took the lead through their skipper Huth.
Fuller's drilled shot from the edge of the box ricocheted off a couple of Birmingham players and Huth was there to lash the ball in off Foster.
It could have got worse for the Blues before the interval but Foster saved a shot from Delap and Fuller got in the way of a Huth header before Clattenburg blew for half-time.
The hosts maintained the tempo after the break as Etherington chipped the ball into the path of Fuller, whose touch let him down with Barry Ferguson looming, and Huth headed a corner wide.
Huth was on hand again to meet Pennant's free-kick but could not get the direction right and then Etherington swung in a dangerous ball which nobody could get on the end of.
Birmingham looked more potent moments later as Jerome cut into the box and hit a low shot which Begovic got down to save, and they went the closest to date when Roger Johnson saw the Bosnian keeper tip his bullet header over.
Suddenly Stoke's lead was looking vulnerable, with Craig Gardner firing a free-kick at Begovic.
Birmingham then almost equalised as a scramble saw Higginbotham hit his own post and Gardner's shot blocked on the line.
Within seconds, though, it was Stoke who had the ball in the net, Fuller twisting and turning before producing a wonderful strike into the top corner.
The points looked safe for Stoke, but only three minutes later Blues substitute Fahey pulled one back after a mistake by Higginbotham.
Alex McLeish's side had come back from 2-0 down in their last game and before Stoke knew what was happening, they had repeated the trick as Jerome glanced Sebastian Larsson's cross past Begovic.
It had taken the Potters only five minutes to throw away a two-goal lead and they looked shell-shocked.
Their opponents smelt blood and Gardner fired one in which Begovic dealt with.
But in the end, it was the hosts who emerged triumphant from the game's crazy climax as Etherington's cross slipped between the legs of Scott Dann and Whitehead pounced, prodding home to seal victory.