The home side took the lead in the 29th minute when Danny Graham bundled home from close range following a corner, and it took Boro little more than a minute to double their advantage.
Jacob Butterfield drilled home Jozsef Varga's cross moments after the restart to give the hosts a two-goal cushion, but there was more drama to come before half time.
Emyr Huws found the net for Birmingham in the 37th minute, putting away Chris Burke's cross from almost 30 yards out to give his side a lifeline at the interval.
Middlesbrough were on top for much of the second period, forcing numerous saves out of Randolph, who did well to deny Jorge Ledesma at point-blank range in the 73rd minute.
They killed the contest off courtesy of a late strike from Lee Tomlin, but the match ended on a sour note for them as Kenneth Omeruo and Ben Gibson were given their marching order after picking up two yellow cards each.