Real Madrid missed the chance to go second in La Liga as Girona came from behind to record a surprise away win.
Casemiro powerfully headed in from Toni Kroos’ deep cross from the right wing to give the hosts a first-half lead.
Cristhian Stuani’s penalty made it 1-1 after Sergio Ramos’ handball and Girona’s Portu then hit the crossbar.
Portu netted the winner with a diving header after Anthony Lozano’s shot had been parried, before Ramos was sent off in injury time for two yellow cards.
The defender had been booked when he conceded the penalty, and received a second caution when he attempted an overhead kick but caught Girona’s Pedro Alcala.
The red card was the 19th of Ramos’ career in La Liga, more than any other player in the Spanish top flight.
It was another controversial moment for the Real captain, who faces a Uefa investigation into whether he deliberately got booked late on in Wednesday’s 2-1 win at Ajax in the first leg of their Champions League last-16 tie – to receive a suspension now and not later on in the competition.