Lewis Wing was on the mark with a neat 37th-minute goal for the visitors but battling Birmingham hit back with Che Adams 79th-minute equaliser, only for Boro to pick themselves up three minutes and win it through substitute Britt Assombalonga.
It was only Birmingham's second Championship home defeat in 19 games and it was a reverse which was hardly a reflection on their committed performance.
Middlesbrough may have run riot in defeating Peterborough in the FA Cup but their prolific goalscoring form deserted them in a blood-and-thunder start.
There was little attacking menace in the first 20 minutes as they found Birmingham to be in combative form and more than holding their own against a top-six side.
When Boro discovered a way through Birmingham's rearguard, Jordan Hugill made a hash of the opportunity. George Saville set up the opening but Hugill miserably misfired well wide from a very good position.
The on-loan West Ham striker could not be faulted for effort and he gave Michael Morrison and Harlee Dean a torrid time in an attempt to break the deadlock.
He came in for some heavy treatment from the Birmingham defenders and as a result referee Graham Scott was questioned by Boro skipper, George Friend.
Almost immediately Birmingham's Maikel Kieftenbeld collected the first booking of the game for a rash tackle on Mo Besic as the game suddenly became more physical.
A fired-up Hugill then had a shot knocked down and Dael Fry latched onto the loose ball only to see Kristian Pedersen block his effort on the line.
This concentrated pressure finally paid a rich dividend for Boro when Saville's cross from the right was tapped in at the far post by Wing for his third goal of the season.
Nine minutes into the second half there was a controversial incident when Adams appeared to be tripped in the penalty area only for the referee to book the Birmingham player for diving.
The game continued to be played at a frantic pace with a catalogue of infringements as Boro desperately
held onto their slender lead.
Only the woodwork saved Boro in the 60th minute when Dean's close range header from a Jota free-kick on the right crashed against the post.
With Birmingham striving for an equaliser Darren Randolph had to show some international form to save a Lukas Jutkiewicz blockbuster through a crowded Middlesbrough defence.
In an end-to-end encounter Birmingham deservedly levelled the score in the 79th minute when Adams played a one-two with Jutkiewicz and fired home a raking drive past Randolph.
But Birmingham's joy was shortlived as Assombalonga, who had replaced Hugill, scored a breakaway goal in the 82nd minute.
Boro boss Tony Pulis was delighted with the victory which keeps Boro within striking distance of the top two in the Championship.
He said: “We were by far the better team in the first half. I know we should have had two penalties in the first half so instead of being one up at half-time we should have been three up at least.
“In the second half they played very direct. I’ve nothing against that because that is the way they play. They have two good forwards, Adams and (Lukas) Jutkiewicz, up there and they put us under enormous pressure.
“We defended extremely well and when they equalised it was going to be tough. But it was a terrific through ball from Wing and Assombalonga finished with aplomb.
“Winning so well away from home shows the character of the team. We had to show it in the second half when we had to dig in against some determined opposition.
“It was a great response to hit back with the winning goal so quickly after Birmingham had equalised.”