The victory dents Madrid's ambitions of retaining the title and leaves the Catalans close to lifting the trophy for the first time since 2019.
Carlo Ancelotti's Real took the lead through a Ronald Araujo own goal but Barcelona pulled level when Sergi Roberto tucked home just before half-time.
Both sides had chances to win the game and Marco Asensio struck for Madrid, but the goal was ruled offside by VAR, before Alejandro Balde set up Kessie in the 92nd minute. "We came from a Marco Asensio goal that we didn't know was offside and from losing, we scored Franck's goal, and the truth is it tastes a bit better, winning like that in the last minute," Sergi Roberto told Movistar. "There are a lot of games left and you can never give Madrid up for dead.
12 points is a tricky distance to have to go, but it's up to us, and that is good." The build-up to the match was overshadowed by Barcelona's corruption charge in the "Caso Negreira" refereeing scandal.