The holders Barcelona set up a Copa del Rey semi-final against Real Madrid after battling to a thrilling 4-2 second-leg win over a stubborn Málaga at the Rosaleda on Thursday.

The La Liga leaders progressed 6-4 on aggregate, with goals from Pedro, Gerard Piqué and late strikes from Andrés Iniesta and Lionel Messi putting them through after Málaga had twice drawn level.

"The two teams have played a great game and now we have the reward of a semi-final against Real Madrid," said Piqué. "We had to work hard to get control of the ball but in the end the result was fair, despite them having also played very well."

Real, the 2011 cup winners, host the first leg of the semi-final at the Bernabéu next week after José Mourinho's side beat Valencia 3-1 on aggregate, despite having two players sent off in Wednesday's 1-1 second-leg draw at the Mestalla.

"On Sunday we have an important league game against Osasuna, I don't want to talk about it," Barça's assistant coach, Jordi Roura, said when asked about the upcoming 'clásico'.

On the other side of the draw Atlético Madrid set up a last-four encounter with Sevilla after drawing 1-1 at their city rivals Real Betis to progress 3-1 on aggregate. Diego Costa scored a valuable away goal, to add to last week's 2-0 victory at the Calderón, after a dreadful misunderstanding in the Betis defence just before half-time.

Chasing a long punt over the top, the Betis defender Antonio Amaya did not see his keeper Casto Espinosa had raced out of the area and he headed the ball past him, allowing Costa to run through and tap into an unguarded net.

La Liga's second-placed side Atlético successfully stifled their hosts until they gave away a penalty in the final minute to concede their first goal in six games in this season's cup competition. The Atlético defender Diego Godin bundled over Jorge Molina in the area and the striker scored from the spot. Sevilla swept aside Real Zaragoza 4-0 on aggregate in their quarter final.

Barça took an early lead in Málaga when Dani Alves broke into the area and crossed for Pedro to head the opener in the ninth minute but it took Málaga only three minutes to level. A quick-passing counter-attack ended with Joaquin slotting a low shot beyond the diving José Manuel Pinto.

Piqué put Barça back in front, chesting down Iniesta's cross and slotting into the corner just after the restart. Barça were now in control but against the run of play, Roque Santa Cruz fired Málaga level again with a low shot off the far post in the 68th minute. Iniesta combined with Cesc Fábregas for Barça's third in the 76th minute, the former Arsenal captain spinning away from his marker to return the ball to Iniesta to score.

Messi headed the fourth, Barça's 100th goal of the season, with 10 minutes to go, effectively ending the game as a contest.