Nathan Tyson hit an 84th-minute winner to earn Nigel Clough's Derby a dramatic victory and increase Birmingham's troubles near the bottom of the table.
Conor Sammon had given the Rams the lead with a header before Marlon King equalised with a penalty after Robert Hall was fouled by Richard Keogh.
Sammon put Derby ahead for a second time before Peter Lovenkrands thought he had earned the Blues a point.
But Tyson's close-range finish sent the visitors to defeat.
Lee Clark's strugglers have won just two of their last 10 games, but they will feel they should have left Pride Park with a point.
Former Wigan striker Sammon opened the scoring in the 32nd minute after Michael Jacobs had struck the woodwork.
King levelled with a 73rd-minute penalty after Keogh's lunge on Hall, playing his first game since signing on loan from West Ham.
That was the first of four goals in 11 minutes - Sammon firing Derby ahead for the second time from 10 yards.
Former Newcastle striker Lovenkrands equalised for Birmingham eight minutes from time.
But with six minutes remaining, Tyson had the final say to lift Derby into 12th.