Sporting Gijon secured promotion to La Liga in sensational circumstances as a stoppage-time goal from Lugo forward Pablo Caballero cruelly denied Girona, while Racing Santander was dramatically relegated on the final day of the season.
Catalan club Girona led Sporting by two points heading into the final game of the season and Francisco Sandaza's 16th Segunda Division goal of the season just before half-time looked to have secured its place in the Spanish top flight for the first time.
With Sporting winning 3-0 at champion Real Betis, Girona needed all three points to seal second spot, but Caballero's downward header two minutes into time added on made it 1-1.
There was still time for more drama, with the home side having what it thought was a winner ruled out for offside and the linesman who raised his flag was rushed down the tunnel after being struck by what appeared to be a bottle.
The game was halted, but when the players returned to complete the final 40 seconds, Pablo Machin's side was unable to come up with a winner and there were emotional scenes at the final whistle as the home side missed out on goal difference.
Girona fans and players were reduced to tears as it faces the prospect of a play-off against Real Zaragoza, while Sporting celebrated being back in the top tier after a two-year absence courtesy of goals from Miguel Guerrero, Jhony and Isma Lopez.
There was also heartbreak for Racing, which will make an immediate return to Segunda Division B despite a 1-0 victory at Albacete.
Javier Pinillos's side looked set to pull off a great escape as Osasuna was trailing 2-1 at Sabadell until David Garcia scored his second goal of the game in stoppage-time to ensure it stayed up by the skin of its teeth.
Racing would have survived due to its superior head-to-head record to Osasuna, but Garcia's late equaliser sent it down in heartbreaking fashion.
Recreativo Huelva, Sabadell and Barcelona B had already been consigned to relegation.
A 2-2 draw at Leganes was enough for Zaragoza to secure sixth spot and a two-legged tie against Girona, which must somehow pick itself up.