Andreas Christensen volleyed Barcelona into a third-minute lead, before Artem Dovbyk headed home his 20th league goal of the season to wipe out the visitors' lead within 60 seconds.
Robert Lewandowski kept his composure from the penalty spot to restore Barcelona's slender lead in first-half stoppage time.
The Blaugrana appeared to be in control until Portu came off the bench to register three goal contributions in a whirlwind 10-minute period.
After pulling his side level, the 31-year-old provided the assist for Miguel Gutierrez's deflected effort, before he produced a stunning volley to help Girona repeat the 4-2 scoreline of December's reverse fixture against Barcelona.
The win moved Girona above Barcelona and into second spot, ensuring that they will participate in the Champions League for the first time in their history.
As for the Blaugrana, the defeat leaves them one point adrift of Girona and 14 points off Real Madrid, who can now celebrate their 36th La Liga title.
Barcelona establish half-time lead
Those in attendance at Montilivi were treated to a thrilling start, with both sides grabbing a goal apiece in the opening five minutes.
Christensen showed all the goalscoring touch of a veteran striker to chest the ball down from Lamine Yamal's pass, before volleying it into the bottom corner.
After being dealt an early setback, the home side produced an instant response through La Liga's top scorer Dovbyk.
The Ukraine international steered his header past Marc-Andre ter Stegen after rising high to meet Ivan Martin's lofted cross.
Girona goalkeeper Paulo Gazzaniga was then required to make a smart stop to deny Ilkay Gundogan shortly before he clawed Christensen's header off the line.
As the game moved past the half-hour mark, Gundogan went agonisingly close to restoring his side's lead, timing his run into the box to meet Joao Cancelo's cross and guide his header against the crossbar.
Girona looked set to go into the break on level terms until Miguel Gutierrez was penalised for a foul on Yamal, presenting Lewandowski with the chance to go to the spot.
Buoyed from Monday's hat-trick, the Poland international stuttered his run to send Gazzaniga the wrong way and roll the ball in the opposite direction.
Portu inspires Girona fightback
Barcelona held onto their lead until the 65th minute when Portu found the net within 30 seconds of coming off the bench.
Dovbyk pounced on Sergi Roberto's weak backpass before teeing up Portu to slide home his sixth league goal of the season.
Within two minutes of the leveller, Girona unlocked Barcelona's defence for the third time to complete a stunning turnaround.
Gutierrez latched onto Portu's cutback, before wrongfooting Ter Stegen with the help of a wicked deflection off Jules Kounde.
True to form, Michel's fearless troops continued to surge forward, with Yangel Herrera forcing Ter Stegen to make a superb reaction save.
Barcelona's fading hopes of rescuing a positive result were ultimately quashed in the 75th minute when Portu produced a breath-taking strike to add a fourth.
Portu latched onto Savio's angled pass to send a spectacular volley beyond the helpless Ter Stegen to pile the misery on Girona's Catalan neighbours.
The hosts threatened to add a fifth in the closing stages, with Dovbyk seeing his effort cleared off the line before Herrera drew a superb save from Ter Stegen.
A fifth goal may have proved elusive, but it mattered very little, as the home faithful celebrated an historic win and their qualification to UEFA's premier club competition.
Barcelona now have a fight on their hands to secure the runners-up spot and a place in next season's Spanish Super Cup.