A double from Lukas Jutkiewicz inspired Birmingham to a 2-1 win and Championship safety to leave Derby deep in relegation trouble.
Derby had taken a first-half lead through Colin Kazim-Richards but Birmingham hit back with Jutkiewicz twice heading past Kelle Roos.
The victory means Birmingham cannot be overtaken but Derby are still in danger after a fifth successive defeat.
Although they are four points clear of the drop zone, Rotherham still have two games in hand and Derby have to get something from their remaining two matches.
One win in 12 games had left Derby looking over their shoulder and the early signs were not encouraging as both sides struggled to keep the ball and create openings.
Derby had a couple of free-kicks just outside the area but the delivery was poor and Birmingham also wasted promising positions with a loose final pass.
The game badly needed a goal and it came in the 36th minute, when Lee Buchanan got behind Birmingham on the left and his low cross was tapped in from close range by Kazim-Richards.
It was the first moment of quality in a game littered by cheap fouls and misplaced passes but as Derby went in at half-time they were edging towards safety.
The second half started positively for County, with Kazim-Richards firing narrowly over from 20 yards and Tom Lawrence making a strong run into the box before a defender stepped across to clear.
Birmingham had not threatened Derby’s goal but that changed in the 57th minute when a cross broke to Kristian Pedersen, who saw a goalbound shot blocked by Matt Clarke.
The visitors were getting balls into the box and they levelled in the 62nd minute when a long throw was flicked on and Jutkiewicz powered a header into the top right corner.
Birmingham should have had another in the 74th minute when a low cross from the right flashed across the six-yard box but Alen Halilovic smashed a shot against a post from a tight angle.
It was a big let-off for Derby but they failed to take advantage as Birmingham scored again in the 84th minute.
A cross was allowed to reach Jutkiewicz at the back post and the striker stooped to head into the bottom corner to leave Derby in trouble.
Martyn Waghorn had a chance to salvage a point in stoppage time but his 20-yard free-kick went just wide.