The result meant that Barcelona climbed into third place to put them behind just Atletico Madrid and Real Madrid. The Catalans are still some distance away from the pair from the capital, but the optics at least will raise spirits.
It was a game that mattered a great deal to both sides, and an action-packed opening period underlined that.
Barcelona hit back inside the opening quarter of an hour. Lionel Messi hiked a high ball crossfield to find Frenkie de Jong at the back post, who brought the ball back across goal for Pedri to score. Unai Simon could have perhaps done better.
Shortly before half-time, the Blaugrana took a deserved lead. Messi played a cute ball in to Pedri, who delayed for a moment before back-heeling into the path of Messi, who had broken, for the Argentine to coolly finish.
Messi struck the upright and had a goal ruled out for offside, but eventually got his team the two-goal cushion they desired. This time, it was Antoine Griezmann rather than Pedri who teed up the Argentine to finish accurately.
Messi gave the ball away late on, however, to open up a play that ended with Iker Muniain curling an excellent effort past Ter Stegen before hurrying his teammates to get back, restart and push for an equaliser. It was too late, however, and the points went home to Catalonia.