In a race that was stopped for 51 minutes due to rain, Alonso looked like being overtaken by Sauber's Sergio Perez until the young Mexican driver ran off the track with six laps to go, giving the Ferrari enough of a gap to win.
The Ferrari team had been considered to be in crisis after a poor off-season and first race, but a superb display of wet-weather driving gave two-time world champion Alonso a memorable victory. Perez's second place was Sauber's best-ever race finish.
Pole-sitter Lewis Hamilton of McLaren finished third ahead of Red Bull's Mark Webber and Lotus' Kimi Raikkonen.
"Its an unbelievable result, a great job from the team," said Alonso, who moved into outright fifth place on the list of career victories, one ahead of three-time world champion Jackie Stewart.
"Its a big surprise to win. We were not competitive in Australia and we were not competitive (in qualifying) here."
Perez's delight with his first podium finish was tempered by the knowledge it could and perhaps should have been an extraordinary win.
"Today a win was possible," Perez said. "I was catching Fernando and I knew I had to get him soon because (on) the sectors with high speed I was losing the front tires.
"I touched the curb and I went onto the dirty side of the track. It was completely wet and I lost the win."
Hamilton finished third from pole for a second straight week, but was glad to have avoided the trouble that struck some championship rivals.
"We would have liked to have more points this weekend but I can't really complain — I'm on the podium for the second race in a row."
Williams' Bruno Senna finished sixth in his best F1 finish, Force India's Paul di Resta and Nico Hulkenberg were seventh and ninth, respectively, separated by Toro Rosso's Jules Vergne. Mercedes' Michael Schumacher took the last point for tenth place, having recovered from a first-lap collision that dropped him down the order.
The race finished in gathering gloom at 6:48 p.m. local time (1048 GMT) due to the long delay caused by a tropical downpour that started after just six laps. Light rain began falling again in the closing laps, but the heavy showers that could have caused another twist stayed away.
Immediately after the restart, there was a flurry of pitstops as drivers changed from full wet to intermediate tires, and Alonso emerged in the lead.
He built his advantage up to 7.7 seconds by lap 30 of 56 but as his tires began to wear, Perez closed in, cutting the gap to 1.3 seconds before both pitted again to switch to dry weather tires.
Perez sliced Alonso's lead to just half a second with seven laps to run and it appeared just a matter of a lap or two until he took the lead. But he critically put one tire on a slippery curb, sending him off the track at the final turn onto the back straight. That gave the Spaniard enough breathing space to hang on for victory, 2.2 seconds ahead of the Sauber driver.
Sauber had notched six third-place finishes in its history, but this was its best result.
World champion Sebastian Vettel of Red Bull was running in fourth place for most of the latter half of the race, but picked up a puncture when he collided with HRT's Narain Karthikeyan with nine laps to go, and finished 11th.
McLaren's Jenson Button also clipped Karthikeyan earlier in the race, dropping him to last before he recovered to 14th. India's Karthikeyan was the innocent party in both incidents.
Alonso moved to the top of the embryonic drivers' championship standings, with 35 points from two races, ahead of Hamilton on 30, and Australian GP winner Button on 25.
Ferrari moved to 35 points in the constructors' championship, trailing leader McLaren on 55 and Red Bull on 42. However Alonso said the win "changes nothing" and said the team still has much work to do to match other teams in qualifying and dry-weather pace.
"It's a tough time for us at the moment but this is a Sunday we will remember," Alonso said. "So this is a positive news but coming to China, Bahrain there is a lot of stuff coming to the car and this is the real job to do.
"We are very united and this win will make us very happy, but it doesn't change our determination to improve the car and to keep winning."Suggest a correction