Goals from Cristhian Stuani and Portu in four second-half minutes cancelled out Isco's opener for Madrid as Real fell eight points behind La Liga leaders Barcelona after just 10 games.
Madrid were making their first appearance in the deeply divided region since a violence marred October 1 referendum plunged Spain into political crisis.
As a reported one million people joined a rally in Barcelona in favour of Spanish unity on Sunday, just over 100 kilometres away in the pro-independence heartland of Girona, the visitors were expected to receive a hostile reception.
“Girona FC's victory against one of the greatest teams in the world is an example and a benchmark for many situations,” Catalan separatist leader Carles Puigdemont, who was deposed by the Spanish government as president of the regional parliament on Friday, posted on Twitter.
La victòria del @GironaFC sobre un dels grans equips del món és tot un exemple i un referent per a moltes situacions. ?
— Carles Puigdemont (@KRLS) 29 October 2017
However, it was events on the field that proved far more troublesome for Zinedine Zidane's men as they lost more ground on rivals Barca in the Liga title race.
“We know we can turn this around. We will have better days and our rivals will lose points over the course of the season,” insisted Zidane. “There is nothing more we can do, and we know that sooner or later things will turn. There is a long way to go and I am not worried.”
Chants in favour of independence and “freedom” reverberated around the 13,500 capacity Montlivi in the 17th minute as is common at Girona and Barcelona home matches to mark the fall of Catalonia in the Spanish War of Succession in 1714.
However, with plenty of Madrid fans present, there were also plenty of Spanish flags on show. “Everyone who knows Girona, knew nothing would happen,” said Girona coach Pablo Machin.
“The fans were sensible. They want it (the political situation) to be over. They enjoyed two brilliant hours of football.”
In their first ever match against the European champions, Girona looked keen to make a mark from the outset and were desperately unlucky not to go in front when Pablo Maffeo's cross came back off the inside of the post 12 minutes in.
Seconds later, though, the ball was in the Girona net as Madrid broke immediately upfield and Isco tapped home the rebound after Bono parried Cristiano Ronaldo's initial effort.
Girona continued to dominate the game and hit the woodwork again before half-time when Portu's flicked header looped over Kiko Casilla and back off the inside of the post.
A Girona fan holds a pro-independence Catalan flag as others hold up placards to form a mosaic before the Spanish league football match Girona FC vs Real Madrid CF at the Montilivi stadium in Girona on October 29, 2017. Photo: Josep Lago/AFP.
Real suffered an injury blow days before they travel to face Tottenham Hotspur in the Champions League on Wednesday as Raphael Varane was replaced by Nacho at half-time due to a muscular problem.
And the French international's presence at the heart of the Madrid defence was badly missed as Stuani jinked past Nacho to fire Girona deservedly level nine minutes into the second-half.
Just four minutes later, Girona were in dreamland as Maffeo's driven cross was flicked home by Portu and the goal was allowed to stand despite the striker appearing to be in an offside position.
“We aren't popping the cava. We're mature and we knew we had a chance to beat a great side,” added Machin.
“Before kick-off it seemed improbable, but we grew throughout the game, the players believed and we did it. We want to continue to be in this league for many more years to come.”
Rather than mount a late comeback as they did so often on route to a first La Liga and Champions League double for 59 years last season, Madrid looked short of energy and ideas in the final half hour as Girona held out for a famous victory.
“We can't make excuses,” Madrid midfielder Casemiro told BeIN Sports Spain. “We have to keep our heads because it is a difficult moment. “We still have a chance but we need to play better and work harder. Madrid
are always obliged to win.”