Real struck first through Cristiano Ronaldo, who later saw red and joined his coach Jose Mourinho in being sent off, but Diego Costa's effort cancelled out the opener.

As the game heated up and got more open, Miranda was the unlikely hero, popping up with a powerful header in the 99th minute, securing the club their first Copa del Rey success since 1996 and first win over Real in 14 years.

Real made a host of changes to the side which drew 1-1 against Espanyol, with Sergio Ramos and Fabio Coentrao returning in defence and Ronaldo, Sami Khedira, Mesut Oezil and Xabi Alonso back in midfield.