Raphinha struck the winner late on after Pedri had cancelled out David Garcia’s early opener.
Barça’s comeback was more impressive given they played for an hour with 10 men. Robert Lewandowski was sent off for two bookings.
Gerard Pique, a substitute on the night, was also sent off at the break for remonstrating with the match officials.
The defender, therefore, never made it on to the pitch for what would have been his 617th Barça appearance. Therefore he brings the curtain down on his career.
After Real Madrid lost to Rayo Vallecano on Monday, Barça are now five points clear at the top of LaLiga and are guaranteed to be top of the league during the World Cup regardless of how Madrid do vs. Cadiz on Thursday.
Barça had made a dreadful start in Pamplona when David Garcia headed in the opener with the referee ignoring pleas for an Unai Garcia foul on Marcos Alonso in the build up.
Things went from bad to worse when Lewandowski was then shown the second red card of his career for a second bookable offence.
Xavi Hernandez’s side regrouped at the break and Pedri drew them level early in the second half.
It looked like the points would be shared. But then in the 85th minute Frenkie de Jong picked out the run of substitute Raphinha. The Brazilian’s brilliant header sealed the win.