Blues had blitzed Millwall 6-0 on their last visit back in January – when the home outfit had seen both Shane Lowry and Alan Dunne sent off – but it looked as if the London side would be the ones handing out a thrashing as they scored three goals in the space of seven first-half minutes.
Striker Chris Wood, on loan from Premier League side West Brom, scored twice, while sandwiched in between was Chris Taylor’s first goal for the south London club.
But King brought Birmingham right back into the match by netting either side of half-time, before completing his hat-trick with a sweet right-foot strike in the 63rd minute.
Birmingham are enduring their worst start to the season since the 1980s – and remain in the lower reaches of the Championship – but King’s wonderful rescue act saw them avoid a sixth defeat in 12 league outings, and lifted some of the gloom.
Millwall, looking to extend their unbeaten sequence to five matches and seeking their first win over their midlands rivals since 1996, had made a dream start to the match.
Frontman Wood had got away from his marker to head in the opening goal from six yards in the 11th minute, and two minutes later Taylor drove home a fierce shot from a similar distance.
Wood then struck again in the 18th minute, meeting Liam Feeney’s right-wing cross with a firm 12-yard shot past England goalkeeper Jack Butland.
Birmingham, who had gone into the game seeking their 300th away win in second-tier league football, grabbed a lifeline in first-half stoppage-time when King collected a pass from strike partner Leroy Lita and despatched a right-footed shot beyond David Forde from six yards.
And the Birmingham forward pair teamed up again four minutes after the break, Lita again finding King in the box and the latter made no mistake with an ice-cool finish from 12 yards.
Birmingham were suddenly firing on all cylinders and in the 63rd minute King completed his treble – and took his season’s tally to seven goals – when he got on the end of David Murphy’s left-wing cross to beat Forde with a crisp right-footed shot into the bottom corner.
The visitors almost snatched a fourth goal after 68 minutes, Nathan Redmond’s 20-yard shot being well saved by Forde.
And the Lions goalkeeper denied Redmond again from even further out 11 minutes from time.
Birmingham kept pressing and King was just off target with a 25-yard right-footed attempt in the 86th minute.