Steve McClaren's side dominated the first half with only Craig Bryson's saved penalty to show for their efforts and it was the inexperienced hosts who took the lead through Brian Howard's 48th-minute header.
The Rams equalised seconds later through Patrick Bamford before Chris Martin and Craig Forsyth seemed to have wrapped up the win for the visitors.
However, Chris Burke's 78th-minute strike kept City in touch before fellow substitute Macheda, signed on loan from Manchester United on Friday, stabbed home an unlikely leveller.
Birmingham, without a home win since October 1, handed debuts to three pre-deadline loan signings, with Manchester United defenders Tyler Blackett and Tom Thorpe featuring along with Manchester City midfielder Emyr Huws. Thorpe's debut lasted barely 10 minutes, though, as he was forced off after landing awkwardly attacking a corner.
Jamie Ward was at the heart of everything going forward for Derby as several tame attempts failed to trouble City goalkeeper Darren Randolph.
Derby's pressure should have told in the 38th minute. Will Hughes' trickery saw him dupe the inexperienced Blackett, who tripped the midfielder and prompted referee Craig Pawson to award a penalty. However, Bryson's low spot-kick towards the bottom-left corner was saved comfortably by Randolph.
The game exploded into life early in the second half. After a dire first 45 minutes, the home side took a shock lead three minutes after the break when Howard flicked home a header from Paul Caddis' right-sided cross to leave Derby goalkeeper Lee Grant with little chance.
Yet less than a minute later it was 1-1 as the Rams caught Birmingham napping. Bamford smashed a shot against the woodwork before reacting quickest to get to the rebound and fire home despite Will Packwood's efforts to block the shot.
Huws dragged a shot wide for the Blues in the 58th minute before Derby went ahead a minute later, Martin trying his luck with a shot which fortuitously came off Bryson's head and into Randolph's net.
Birmingham boss Lee Clark immediately sent on another debutant, Macheda, in place of Lee Novak as he sought a response. But Forsyth capitalised on some slack defending to slot home the third after more good work by Ward.
Macheda should have done better from close range at the other end before fellow substitute Burke made things interesting with a 78th-minute strike, cutting inside and bending the ball beyond Grant.
The leveller came more than three minutes into injury-time as Huws flicked Albert Rusnak's corner onto the post and Macheda gleefully smashed in the loose ball.