The clock had ticked past the allotted minimum of six minutes of added time when the ball reached Wilfried Zaha deep on the left. Crystal Palace had given everything in their demented pursuit of an equaliser in the second half. Joe Hart had made save after astonishing save, including one from James Tomkins in the 91st minute, and they had hit the woodwork twice. They were falling agonisingly short. As Robert Madley prepared to blow for full time, a ninth defeat in 10 matches beckoned for the Premier League’s bottom side.

This, however, was football at its barmiest. West Ham were coasting at half-time, smart goals from Javier Hernández and Andre Ayew setting them on course for their first away win this season, but they were reduced to a rabble in the end, Zaha’s moment of opportunism the spark for a total loss of composure from Mark Noble, who had to be pulled away from Ruben Loftus-Cheek shortly after the final whistle.

You could understand the West Ham captain’s irritation at the way his team had blown a chance to pull clear of the bottom three. Moments before the leveller, Michail Antonio had possession deep in Palace territory. He just had to eat up a bit more time, but instead his needless cross found Julián Speroni. “To concede in that manner is very frustrating,” Slaven Bilic said. “All we had to do is keep the ball for five seconds. It’s very frustrating. It feels like a defeat.”

It felt like a win for Palace, even if they remain in deep peril after this draw. “I don’t know if it’s sweeter than the win over Chelsea,” Roy Hodgson said. “But I do think it’s showed me this team has more character than they’ve sometimes been credited for.”

Wilfried Zaha celebrates after rescuing a point for Palace. Photograph: Zemanek/BPI/Rex/Shutterstock

Hodgson was right. It would have been easy for Palace to capitulate when they trailed 2-0. There was a tinge of sympathy to the applause that greeted the home players as they made their way down the tunnel at the break, even if it was meant as a show of support, and an unmistakable air of resignation filled Selhurst Park when Ayew, a man transformed after his midweek heroics against Tottenham Hotspur, rocketed a brilliant left-footed drive past Speroni from the edge of the area in the 43rd minute.

Not that Palace deserved to find themselves two goals down at the end of a slow-burn first half. There was not much between the sides during the opening stages and the game took a while to ignite after Palace lost Patrick van Aanholt to an early hamstring injury.

Nothing went Palace’s way in the opening period. After 30 minutes of scrappiness, one sharp burst summed up their misfortune. They were still seething at Zaha being refused a penalty for Jose Fonté’s clumsy challenge when West Ham countered, taking advantage of a loss of focus that offered space to Manuel Lanzini for the first time. The ball ran from Lanzini to Ayew to Aaron Cresswell and the left wing-back’s pass reached Hernández, who demonstrated his poaching instincts with a classy stabbed finish.

Without the injured Mamadou Sakho, Palace’s defence started to creak and West Ham doubled their lead after Hart’s spectacular double save from Tomkins and Jeffrey Schlupp. Ayew robbed Luka Milivojevic near halfway, ran at the exposed Palace defence, stepped past Scott Dann and notched his third goal in two games.

Bilic looked like a condemned man a week ago. Now the pressure was lifting on West Ham’s manager, who had inspired that sensational fightback against Tottenham, but he ended up accusing his players of naivety.

Palace might have lacked a recognised forward, with Christian Benteke and Connor Wickham injured, but they had heart. Angelo Ogbonna foolishly tripped Andros Townsend in the 50th minute and Milivojevic halved the deficit from the spot. “Teams at the bottom need two things,” Hodgson said. “Character and ability.”

With West Ham tiring, Fonté and Cresswell went off injured and the visitors lost their shape. Palace poured forward. Cabayé hit the post and threatened with a free-kick before Hart pushed a Tomkins header on to the bar. Bakary Sako somehow turned the rebound over.

It seemed that Palace’s chance had gone, but Zaha kept pushing. Hart had denied him twice before he embarked on one last dribble. He cut inside, his low shot squirmed through the mess of legs and this time Hart had no answer. For a second there was disbelief and then there was earsplitting noise, taunts towards the away end and wild celebrations. These are the moments that save seasons.