Charles N'Zogbia's 94th-minute goal extended Wigan's unlikely six-year Premier League adventure by at least another week as relegation cost West Ham's Avram Grant his job.
The Hammers were already on their way to the Championship, having squandered their two-goal lead, when N'Zogbia cut in from the right to beat Robert Green at his far post with a perfectly placed low shot.
Wigan might still be favourites to take the drop themselves, but their supporters burst on to the pitch on the final whistle, celebrating as though they had not merely avoided relegation but won the Champions League.
The euphoria might be temporary, but this result was a triumph for manager Roberto Martinez' half-time tactical reshuffle. "We have many, many options in the squad and we had to take risks," he said of his decision to bring on two impatient young attackers, Victor Moses and Conor Sammon, and move the hitherto quiet N'Zogbia into a more central role.
The pay-off was almost instantaneous. N'Zogbia was fouled by James Tomkins just outside the area, won the debate over who should take the free-kick and smashed it left-footed into the top-left corner.
"The Great Escape" was back on the schedule. After 67 minutes, Ben Watson found Sammon, the big Scottish striker taking a couple of slightly ponderous touches before finding his feet and firing past Green.
With perfect timing, a plane circled over the ground, with a trailing banner that read: "Avram Grant Millwall Legend."
"We had a real mountain to climb at half-time, but that's when the character comes through," Martinez said. That character may yet prove insufficient to keep them in the top division, but at least Wigan have given themselves a chance.
For half the game, though, the trusty left foot of Thomas Hitzlsperger and the head of Demba Ba seemed as though they might preserve a much-changed West Ham's slender Premier League lifeline.
Scott Parker, so often cast in the role of potential saviour this season, was only fit enough after his Achilles injury to take his place on the Hammers bench, where he had plenty of company from others also more familiar with a berth in the starting line-up. The general opinion was that the substitutes looked stronger than the team.
Wigan limited their changes to the recall of Mohamed Diame as an extra central midfielder. It smacked a little less of panic than Grant's selection, made in spite of the Hammers' encouraging record of five wins in their eight visits to the DW Stadium.
It looked promising enough for the Latics in the opening minutes. Tom Cleverley, the loan signing from Manchester United who has been such an asset this season, had one shot pushed around the post and set up another for Diame that went too high.
Gary Caldwell picked out Hugo Rodallega with a through-ball, but he shot straight at Green and, not for the first time this campaign, all Wigan's neat football amounted to nothing.
The West Ham fans who packed the away end had done their sums and knew what they thought of both teams' survival chances. "You're going down with the West Ham," they sang and, as soon as the partnership of Hitzlsperger and Ba got at the Wigan defence, that began to look the likely outcome.
The German pounced on an indecisive clearance to whip the ball in for the first goal, headed home powerfully by Ba. Wigan had hardly recovered from that when Hitzlsperger delivered a free-kick from the left with equal precision. Tomkins won it in the air beyond the far post and Ba was there again to finish it off. Ba Humbug, as they might say in the town that gave the world Uncle Joe's Mintballs.
It could have been worse if Watson had not cleared off the line from Frédéric Piquionne, but Wigan continued to enjoy more than their share of the possession without being able to take any of their chances.
Rodallega had an overhead kick well-saved and Diame was also frustrated by Green. The West Ham goalkeeper knew little, however, about the block he made from Rodallega's effort when the ball came back in from the resulting corner.
Green's luck ran out in the second half, although he could do little about any of the goals. He is one of the players now likely to join the exodus from Upton Park, led by Grant.
The manager played a dead bat about his own future in the immediate aftermath. "I'm not thinking about myself while I'm in this room. I'm just so sorry for these supporters. I wanted to do well for them," he said, pointing to the chance for a Ba hat-trick at 2-1 that could have brought a different result. That is all in the past for West Ham now, but for Wigan the glorious uncertainty goes on, at least until they play Stoke City on Sunday.
One thought had to occur to anyone watching this most exhilarating and dramatic of matches. If these two teams had displayed the same sense of urgency throughout the season they would not have been in this plight on its penultimate Sunday.
Substitutes: Wigan Moses (McCarthy, h-t), Sammon (Cleverley, h-t), McArthur (Rodallega, 90). West Ham Parker (Spector, 60), Cole (Piquionne 74), Keane (Collison 83). Unused Kirkland (gk), Gohouri, Gomez, Di Santo, West Ham Boffin (gk), Upson, Da Costa, Sears. Booked: Wigan N'Zogbia West Ham Parker. Man of the match N'Zogbia.
Match rating 8/10. Possession: Wigan 50% West Ham 50%. Attempts on target: Wigan 9 West Ham 3. Referee M Dean (Wirral).
Attendance 22,043.Reuse content