The Hammers could not have had a worse start as Mateusz Klich opened the scoring at the second attempt from the penalty spot after Lukasz Fabianski was penalised for coming off his line in saving his Poland international team-mate's first spot-kick.
However, David Moyes's men exposed Leeds's struggles to defend set-pieces to move within a point of the top four.
Tomas Soucek levelled by heading in Jarrod Bowen's corner, although Leeds goalkeeper Illan Meslier should have done better.
The winner arrived in similar fashion as Ogbonna powered in Aaron Cresswell's free-kick 11 minutes from time.
West Ham was inches away from another set-piece goal when Fabian Balbuena hit the post, but the visitors comfortably held out to continue their impressive season so far.
A fourth defeat in six games leaves Leeds 14th in its first season back in the top flight for 16 years, but with an eight-point cushion above the relegation zone.