Brian Howard opened the scoring for Birmingham early in the second half before Chelsea young gun Patrick Bamford responded swiftly with his fourth goal in his fifth Rams appearance when following up his initial effort which struck the woodwork.
Goals from Chris Martin and Craig Forsyth had Derby 3-1 ahead by the 73rd minute before Chris Burke pulled one back for Birmingham with just over ten minutes remaining.
Macheda, who had earlier replaced Lee Novak, was the hero for the Blues in the 93rd minute when he fired home from close range after Manchester City loanee Albert Rusnak's corner had been flicked on by fellow City youngster Emyr Huws.
Birmingham boss Lee Clark was thrilled with the debut of Macheda who had only been brought in late on Friday.
"Federico didn't meet his team-mates until 12.30pm today so that's probably why he started on the bench. But he made a huge contribution and looked bright," he said.
For breaking stories and all the great banter like us on Facebook: facebook.com/tribalfootball