Defending champions Barcelona went ahead on the night after just nine minutes when Pedro Rodriguez headed in a cross from Dani Alves after good work by Xavi.
But Joaquin Sanchez, with a right-foot drive, levelled for Malaga three minutes later.
Four minutes after the interval, Gerard Pique, who became a father for the first time this week when pop star girlfriend Shakira gave birth to a son, marked the occasion by volleying in Barcelona's second.
Roque Santa Cruz controversially equalised in the 68th minute after a Malaga counter-attack. But Barcelona were furious that Cesc Fabregas had not been awarded a penalty when he was stamped on by Wellington.
Eight minutes later Andres Iniesta made it 3-2 after a smart one-two with Fabregas before Lionel Messi grabbed Barcelona's fourth of the night, heading in an 80th-minute cross from Iniesta for a 6-4 aggregate. In the night's other tie, Atletico Madrid drew 1-1 at Real Betis for a 3-1 aggregate and a semi-final clash against Sevilla.
Thursday’s Results Real Betis 1, Atletico Madrid 1 (Atletico advance 3-1 on aggregate) Malaga 2, Barcelona 4 (Barcelona advance 6-4 on aggregate).