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.
Ramos had been quoted as telling reporters he would “be lying if I said I didn’t force [the booking]”, but later posted on social media that he had “not forced the card”.
Real, who started the weekend in second place in the table, are now third, nine points behind leaders Barcelona, who won 1-0 against Real Valladolidon Saturday.
Atletico Madrid are now second, two points clear of city rivals Real, following their 1-0 victory over Rayo Vallecano.
Real boss Santiago Solari made six changes to face Girona, with Wales forward Gareth Bale among the substitutes and midfielder Luka Modric missing through suspension.
Away keeper Yassine Bounou denied Lucas Vasquez before Casemiro’s header gave the hosts the lead. Karim Benzema and Marcelo had further chances saved, and Benzema also headed into the side netting as Real pushed for a second.
However, the visitors – who had not won in their previous 13 matches – fought back. Aleix Garcia wastefully shot over from six yards out and Stuani headed against the post before Ramos charged down the follow-up shot with his hands and Stuani equalised from the spot.
Bale came on in the 67th minute, but was unable to prevent his side losing their grip on the match. Portu hit the crossbar and then scored a 74th-minute winner to severely dent Real’s hopes of becoming Spanish champions this season.