Barcelona have set up a Copa del Rey semi-final showdown with Real Madrid after defeating Malaga 4-2 in the second leg of their thrilling quarter-final tie.
With scores locked at 2-2 from the first leg, it was Barca who gained an early advantage at La Rosaleda when Pedro Rodriguez finished off a well-crafted team goal in the eighth minute.
The celebrations were short lived as Joaquin equalised for Malaga just four minutes later, with the hosts holding out until half time.
Barcelona restored their lead shortly after the break when Gerard Pique found the net, but a resilient Malaga once again drew level with Roque Santa Cruz breaking through in the 68th minute.
Just as the match looked headed for extra time, Andres Iniesta combined with Cesc Fabregas to score in the 76th minute, before Lionel Messi headed home his 40th goal of the season to seal the win.
Barca will now face Real Madrid in the Copa for the third consecutive year, with the winner of that match set to face the winner of the other semi-final between Atletico Madrid and Sevilla.
Atletico eliminated Real Betis earlier on Thursday, with a 1-1 draw enough to see them through 3-1 on aggregate.
Diego Simeone's side had a comfortable 2-0 first leg lead and they extended the advantage with a Diego Costa goal on the stroke of half time.
Betis were never in the match and a last-minute penalty from Jorge Molina was a mere consolation for the hosts.
Information from Press Association and The Associated Press was used in this report.