The fourth-round replay was heading for a penalty shoot-out when centre-half Ogbonna, thrust into attack as a final throw of the dice, headed in the winner. The final score, WHU – Liverpool 2-1.
West Ham can now look forward to a fifth-round trip to Blackburn after a youthful Liverpool side were eventually sent tumbling out.
Michail Antonio had given the hosts the lead, only for Philippe Coutinho to reply for the Reds just after half-time.
But Ogbonna made it an uncomfortable evening to be a losing manager, not least one who had had his appendix removed just three days earlier like Jurgen Klopp.
The home fans knew this was likely to be the last FA Cup tie under the lights at Upton Park, and the famous old ground crackled with an atmosphere it will surely be impossible to recreate at the Olympic Stadium.
The match was worthy of the occasion, as well. In a breakneck first half alone, West Ham were twice denied by the woodwork, while Liverpool also rattled a post before Antonio broke the deadlock.
Hammers full-back Joey O’Brien was first to be frustrated by the frame of the goal when his shot was deflected against the base of Simon Mignolet’s upright.
But Liverpool’s rookies, aided by the experience of Coutinho and out-of-favour striker Christian Benteke, looked the more dangerous in the early stages.
The senior duo combined when Benteke reached the byline and cut the ball back for Coutinho, whose first-time shot clipped an upright.
Moments later West Ham playmaker Dimitri Payet, reportedly the subject of a big-money bid from a Chinese club, curled a superb free-kick against the post.
Antonio headed the rebound back towards goal but Mignolet did brilliantly to scramble back to his feet and make a diving save.
The breakthrough came on the stroke of half-time when Enner Valencia crossed to the far post, where Antonio side-footed a volley into the back of the net.
Yet the lead lasted less than three minutes of the second half, after Liverpool were awarded a free-kick on the edge of the box.
Coutinho shaped to curl the ball over the West Ham wall, but as the players jumped the Brazilian cheekily drove it underneath them and past startled goalkeeper Darren Randolph.
West Ham were convinced they should have had a penalty when Tiago Ilori pulled back Valencia as he attempted to reach Antonio’s cross, but referee Roger East did not agree.
Valencia could have won in normal time but headed Payet’s cross over, while Benteke and Jordon Ibe forced saves from Randolph.
Early in extra time Mignolet was in action again to palm away a curler from Mark Noble before Benteke passed up two clear-cut chances, blazing wide from 16 yards before firing too close to Randolph.
Then England striker Daniel Sturridge, on as a substitute for Liverpool after another spell out injured, fired a rasping drive inches over the crossbar.
But as the clock ticked down Ogbonna trotted forward and managed to get his head to Payet’s free-kick to spark delirious scenes among the Upton Park faithful.