The hosts could have taken the lead after 24 minutes when Barca goalkeeper Victor Valdes brought down Angel Lafita for a penalty. However, Valdes was able to get down to low to save Carlos Aranda's spot kick and keep the scores level.
Zaragoza made the breakthrough six minutes later when Aranda inventively headed in the rebound after Valdes had saved the striker's initial shot with his legs.
Barca took the lead soon after as Lionel Messi lashed the ball home after a quick counter-attack.
Despite being kept at bay for large spells of the second half, Barcelona stretched their lead with five minutes to play as Messi converted from the spot following Javier Paredes's foul on Sanchez.
Pep Guardiola's side sealed the win in the second minute of injury time when Messi played in Pedro with a chipped pass to allow the midfielder to fire in.