Hosts Lazio looked to have salvaged a share of the spoils at the Stadio Olimpico when late substitute Filip Djordjevic headed Miroslav Klose's headed cutback past Morgan Da Sanctis in the Roma goal to level Juan Iturbe's 73rd minute opener for the visitors.
A draw would have secured at least a third-place finish for Lazio and a place in the Champions League play-offs.
But Yanga-Mbiwa turned the match on its head with a glancing header from a free kick five minutes from time to secure the points for Rudi Garcia's side.
The result leaves Roma in second place, 16 points behind recently-crowned champions Juventus but four ahead of Lazio with one game remaining this season.
“Our objective this season was to qualify directly for the Champions League, and we've achieved that,” Garcia told reporters.
“Obviously when you win like this, having conceded a late leveller like we did, it only adds value to all the work we've done in recent weeks to prepare for this game.”
Lazio remain third but Stefano Pioli's men, who sit three points ahead of Napoli, now require a point from their trip to Naples in their final game of the campaign next week, when Roma host Palermo.
“Today it's only right we should hang our heads. We lost the game when we had ample opportunity to score goals,” Pioli told reporters after the match.
“Roma were better than us in the decisive moments. If we'd taken the lead when we had the opportunity to, it would have changed things tactically for us.
“We tried to play our game, and we put our opponents into difficulty but in the end we conceded to a team that were superior in terms of scoring goals.”
If unsuccessful, it would be a spectacular fall from grace for Lazio, who have been playing some of the best football in Italy's top flight since January.
But Pioli added: “We'll go to Napoli to fight for the result that we need.”
Lazio came into the derby with tired legs after a 2-1 Cup final defeat to Juventus last week and had a lightning start only to spurn two clear chances for an early lead.
Italy international Antonio Candreva forced a reflex save from Morgan De Sanctis from a tight angle and Roma survived a bigger scare moments later when nerves a poor Vasilis Torosidis clearance fell to Candreva, who delivered a perfect ball into the box as Klose ghosted in only to power a header wide of the right post.
Roma had little to offer in a shaky opening half and Lazio started just as strongly after the break, Dusan Basta pouncing on a poor headed clearance from Torosidis to fire low inches past De Sanctis's far post.
A Senad Lulic challenge on Francesco Totti which left the captain rolling on the ground was the first flash point of the second half and the defender, issued one of his side's three yellow cards in a feisty opening half, was lucky to escape a second caution.
He was replaced by Luis Cavanda soon after as Lazio kept the momentum, threatening just before the hour when Klose headed back into the area for Stefano Mauri to see his overhead kick blocked.
A tiring Totti came off for Victor Ibarbo, a move that would pay dividends for Garcia's men, the Colombian holding off his marker to sweep across goal for Iturbe to stab the ball past Federico Marchetti at the back post.
The stadium erupted eight minutes later when Djordjevic, who had replaced Mauri after 76 minutes, ran into the box to head Klose's header from the right byeline past a flailing De Sanctis after Felipe Anderson's cross in deep.
But with five minutes on the clock, Roma were given a lifeline when they won a free kick to the right of the Lazio area.
Miralem Pjanic stepped up to deliver and Yanga-Mbiwa rose unchallenged to see his glancing effort roll past Marchetti at the 'keeper's far post.