Visiting Barca started the brighter of the two sides and went on to break the deadlock with seven minutes on the clock. Having missed a chance moments earlier, four-time Ballon d'Or winner Lionel Messi made amends by sending the ball into the home side's net from inside the area following a pass by Andres Iniesta.
Barca continued to be the dominant force and went close to doubling their advantage with 14 minutes played. A passing move eventually found Pedro, but the Spanish international's effort rebounded to safety off the post.
© AP Photos
However, Pedro did not have to wait too long to get his name among the scorers. Dani Alves was the creator, squaring the ball for his teammate to tap into an unguarded net in the 25th minute.
Messi thought he had his second and Barca's third in the 39th minute, but his lofted effort struck the inside of the post and rolled along the line before it was hacked to safety.
They made the most of their numerical advantage with 63 minutes played when Castro claimed his second of the evening courtesy of a deflection off of Barca defender Javier Mascherano.
It looked as though both teams were going to have to settle for a share of the spoils until Agirretxe found himself free inside the area deep into stoppage time and he rolled the ball into the net from six yards out.
The defeat is Barca's first of the season and their first since April 2012.