Cristhian Stuani played for Middlesbrough for two years before joining Girona in 2017
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 a Girona player.
The red card was the 19th of Ramos' career in La Liga, more than any other player in the Spanish top flight.
Home goalkeeper Thibaut Courtois went up for a corner in the 95th minute and headed goalwards but missed the target.
Real, who started the weekend in second place in the table, have slipped to third, nine points behind leaders Barcelona, who won 1-0 against Real Valladolid on 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, with Wales forward Gareth Bale among the substitutes and midfielder Luka Modric missing through suspension.
Girona 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.
'A fair result' - what they said
Girona manager Eusebio Sacristan said: "It's really important for us to win at the Bernabeu - for our fans, for our team.
"Maybe they were thinking they would get a second goal, but we were slowly getting back into it and getting more confident. At the end of the game it is a fair result.
"We had not won for a few games and had a tough few weeks. But we showed our attitude, and what better ground to do it in."
More to follow.