In a race of rare drama, Sebastian Vettel looked a certainty to win a third straight race at the street circuit, only for a technical problem to force his retirement.
Romain Grosjean, the man in the best position to challenge Alonso, also retired after losing his gears.
Lewis Hamilton was running in second place until tyre wear caught up with him in the final few laps, and Grosjean's team-mate Kimi Raikkonen went past him to take second place.
Hamilton still looked likely to take third place despite the attentions of Pastor Maldonado, but on the penultimate lap the two crashed allowing Michael Schumacher to steal through and take third, his first podium finish since his return to the sport in 2010.
Valencia has drawn criticism in the past for a lack of overtaking and atmosphere, and this looks set to be the last time the Grand Prix appears on the calendar. If that proves to be the case, it has bowed out with a race for the ages.
Alonso won the race for the first time, combining ambition and daring with superb Ferrari strategy and pit-work to climb 10 places and give the home fans a result to savour.
It made the Spaniard the first man to win two Grands Prix this season, and the new championship leader, with both his key rivals going pointless, and he was on the verge of tears as the national anthem played.
But there were stories all over the racetrack. Mark Webber surged from 19th to finish fourth, while Force India had their result of the season with Nico Hulkenberg fifth and Paul di Resta seventh.
Nico Rosberg picked up five places in a frenzied final few laps to rescue sixth place on a day he looked destined to go without points.
Jenson Button missed out on much of the excitement, but managed to drag his McLaren home in eighth to improve on a poor sequence of results. Sergio Perez took ninth, while Maldonado nursed his car, damaged in the Hamilton clash, round to 10th.
The Venezuelan may yet lose that point on appeal as the incident was one of several requiring the stewards' attention.
Hamilton had lost grip in his rear tyres and Maldonado was clearly faster, but having defended against the Williams, forcing him off the track, Maldonado swung back in to Hamilton and took him out.
The championship leader at the start of the day did not hide his disgust, throwing his wheel out of the car once he realised his race was over.
Hamilton had had a topsy-turvy day - distinctly second-best to Vettel, who bossed the race emphatically until the introduction of the safety car midway through the race, after an incident between Jean-Eric Vergne and Heikki Kovalainen which left rubber all over the track.
Vettel surrendered the 20-second lead he had built, while Hamilton, who had lost second place to a passing move of astonishing bravery from Grosjean, then lost more time after yet another McLaren hold-up in the pits.
That was the moment when Alonso truly burst into the race, leapfrogging Hamilton in the pits, getting the better of Grosjean when the safety car pulled in, and easing into the lead when the reigning world champion ground to an abrupt halt after 33 laps.
Hamilton, initially dropped to sixth by the gaffe, looked to have salvaged second place through others' misfortunes until his luck deserted him in the dying moments of the Grand Prix.
There was not to be an eighth different race winner in eight races, but for incident and excitement this was hard to match.