Victor Obinna kept West Ham's FA Cup dreams alive with a superb hat-trick in a thrilling encounter at Upton Park.
The striker scored twice in the first half and then slotted home a penalty in the second as the hosts put their Carling Cup semi-final misery behind them and set their sights on another potential route to Wembley, with Burnley next for them in the fifth round.
They had to rely on a healthy slice of fortune against a Nottingham Forest side who demonstrated just why they are pushing for a Premier League place next season.
But while the much-changed Hammers struggled at times in defence, they showed enough penetration up front to give manager Avram Grant hope that they can turn around their desperate first half of the season.
With Grant having strengthened his squad with the signings of Gary O'Neil and Demba Ba, plus Wayne Bridge on loan and possibly more to follow before the transfer window closes, the manager was hoping for a much-needed cup boost.
There was no doubting where his priorities lay, however, making nine changes to the side knocked out of the Carling Cup in the semi-final by Birmingham in midweek.
Scott Parker started on the bench, kept in reserve for the league match against Blackpool on Wednesday.
The Hammers could hardly have enjoyed a more encouraging start, taking the lead after just three minutes.
The goal came following a corner when the ball was rolled back to Mark Noble whose right-footed shot looked to be flying well wide until Obinna deflected it past Forest goalkeeper Lee Camp.
Forest, however, responded well, Radoslaw Majewski in particular causing the West Ham defence problems.
The inevitable equaliser came after 17 minutes following a period of sustained Forest pressure during which 35-year-old Nigerian striker Dele Adebola showed the most determination to drive into the penalty area to send his shot past Hammers goalkeeper Robert Green for his first goal of the season in the 22nd match in which he has been involved.
In truth, West Ham's defenders struggled to cope in that first half with a lively Forest attack.
All the incisive football came from Forest and it was no surprise when they took the lead after 39 minutes.
This time it came from a free-kick on the right floated in by Chris Cohen. The ball was flicked up in the air by a flapping Robert Green, only for David McGoldrick to head home from close range.
It was not Green's finest moment but two minutes later West Ham were back level and this time it was a spectacular effort, although there appeared to be more than a touch of fortune.
Obinna charged down the right and sent in a a 30-yard shot from an acute angle which flew over the head of goalkeeper Camp. Only Obinna knows if it was really intended as a cross but it was certainly a goal with a freakish quality to it.
When the hat-trick goal arrived in the 52nd minute it was more down-to-earth, with Joel Lynch bringing down Winston Reid and referee Michael Oliver having no hesitation in pointing to the spot.
Obinna stepped up to coolly complete his treble, before wheeling away and treating the crowd to half a dozen somersaults in celebration.
The Hammers might have had more, Camp saving brilliantly twice from Frederic Piquionne and once from Pablo Barrera.
And in the end they deserved their place in the fifth round. Grant even managed a smile. Things must be looking up.