Keigan Parker scored a sensational winner two minutes from time to earn a reprieve for under-pressure Huddersfield Town boss Stan Ternent.
Parker, who has been beset with off-the-field problems, made a rare start and produced a fabulous individual strike into the top corner.
Ternent, whose side had won just once in seven matches, seemed to be heading for the exit after Huddersfield conceded a two-goal lead.
But Parker rescued his manager - and his season - with the winner although he ended up being sent off deep into stoppage time. Booked in the first half, he was dismissed for a second yellow for handball.
Huddersfield went ahead through centre-back Andy Butler who caused havoc in the Crewe defence.
Butler's header from Gary Roberts' cross was blocked on the line by Danny O'Donnell. The ball came back to Butler whose close-range shot came off O'Donnell and keeper Steve Collis and went in.
Huddersfield doubled their lead just before half-time when Parker's cross was headed out by John Brayford and Ian Craney produced a superb curler which almost matched Parker's winner for brilliance.
Two minutes later Crewe were back in the game when Clayton Donaldson shrugged off the suspicion of offside to race through one-on-one with keeper Matt Glennon to score.
Alex came out after the break in a much more positive manner and equalised on the hour with another controversial strike through Donaldson.
If the striker's first goal looked offside, the second was even more dubious but again there was no flag.
Byron Moore's breakaway set Donaldson free and he kept his cool to beat Glennon once more.
That sparked furious scenes among the home fans and a missile appeared to be thrown in the direction of the linesman.
Just when two 'offside' goals seemed to have done for Ternent, Parker produced a moment of magic only to be given his marching orders in the fourth minute of stoppage time.
Parker claimed afterwards he put his hands up to protect himself and Ternent will look at the video before deciding on an appeal.