The Robins, with only one away win all season going into Saturday's Championship match at the Riverside, took a shock lead in foggy conditions through Albert Adomah, a goal Boro keeper Jason Steele will not want to see again, but high-flying Boro drew level before the break when Ismael Miller netted after a penalty-area scramble.
Shortly after the hour mark, Pearson put the Robins back in front and the vital victory was sealed with just three minutes to go when Steven Davies netted.
Boro, looking to bounce back from a 1-0 defeat at Cardiff last weekend, made three changes with Stuart Parnaby, Miller and Marvin Emnes coming in after injuries to George Friend and Faris Haroun while Scott McDonald started on the bench.
Bristol City halted a run of seven successive defeats at home to Blackpool last week and Derek McInnes was forced into two changes. Former Boro man Matthew Bates suffered a hamstring problem in training so Louis Carey was given the nod while Ryan Taylor replaced the injured Jon Stead up front.
The home side had two early half-chances through Miller and then Grant Leadbitter but it was the visitors who took a shock lead after 13 minutes. Joe Bryan got to the byline and teed up Adomah and his effort from just inside the six-yard box went underneath Jason Steele.
Four minutes later, Boro striker Lukas Jutkiewicz had a fantastic chance to drag his side level but he headed wide when well placed after a pinpoint cross from Miller.
At the other end City had a great chance when Taylor set up Pearson but he fired well over the crossbar.
Taylor was causing the Boro defence all sorts of problems and shortly after missing a good chance he felt he should have had a penalty, believing he was fouled by Andre Bikey.
With 34 minutes on the clock, the home side made them pay for their profligacy when Miller fired home his third goal of the season from close range after a Leadbitter corner was not cleared and scrambled into the path of the former Manchester City striker.
In the second half, City keeper Tom Heaton punched the ball against his own post before Neil Kilkenny hacked the ball clear and at the other end Adomah came close to a second of the afternoon.
The lead was restored with only City's eighth away goal of the season in the 63rd minute when Leicester loanee Neil Danns teed up Pearson who fired home from inside the box to delight the travelling support.
Just five minutes later, Heaton had to make a top-class save to deny substitute McDonald to keep the lead intact.
With two just minutes to go, a memorable victory for the visitors was complete when substitute Davies curled home his eighth of the campaign from Adomah's pass.