Barcelona started the match as league leaders, but Madrid created the first clear opportunity when Arda Guler intercepted a misplaced pass from Pedri before firing over the crossbar.
Barca suffered an injury setback midway through the first half when right-back Xavi Espart was forced off and replaced by Alejandro Balde. Madrid took advantage of the disruption, with Mbappe eventually opening the scoring four minutes before half-time when Gerard Martin's attempted clearance rebounded off the French forward and into the net.
The goal was Mbappe's 10th in La Liga this season, underlining his importance to Madrid's title challenge. Barcelona threatened before the break, but Lamine Yamal and Yan Diomande both missed opportunities to equalise.
The hosts responded strongly after half-time and were rewarded in the 61st minute. Raphinha, Barcelona's leading scorer, found space inside the penalty area before guiding a finish into the far corner to make it 1-1.
Madrid immediately pushed for another goal, with Guler testing Joan Garcia, while Barcelona goalkeeper Andriy Lunin produced an outstanding reflex save to deny Martin's header at the other end.
Barcelona looked capable of snatching victory as Yamal sent an effort narrowly wide and Frenkie de Jong saw a late shot blocked. However, Madrid delivered the decisive blow three minutes from time.
Eduardo Camavinga reached a through ball ahead of Garcia before squaring for Mbappe, who finished from close range to secure all three points for the visitors.
The victory gave Madrid their first win at the Nou Camp since October 2023 and ended Barcelona's run of 23 consecutive home league victories. Madrid also extended their unbeaten run against Barcelona under Jose Mourinho to six matches.
Madrid remain third in the standings but have moved to within three points of their rivals, keeping the pressure on Barcelona in the race for the La Liga title.