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.
He had been booked when he conceded the penalty, and received a second caution when he attempted an overhead kick but caught a Girona player.
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.