Shaun Derry celebrated his home debut with an 86th minute winner against his favourite opponents as Leeds United ended West Ham's three-match winning league run.
Derry, Leeds' bargain £250,000 buy, helped Crystal Palace to promotion through the play-offs last season when the Hammers were beaten in the final at Cardiff.
And he haunted the same side again, taking David Healy's pass before expertly clipping the ball past keeper Stephen Bywater from eight yards.
Former Yeovil and Hereford winger Gavin Williams thought he had rescued a point for the promotion-chasing Hammers with a 68th minute equaliser after Rob Hulse had volleyed Leeds into a 51st minute lead.
Williams, who also hit the Leeds post on 55 minutes, fully justified Alan Pardew's decision to restore him to the side in place of Nigel Reo-Coker.
Leeds had a penalty shout rejected when Gary Kelly's 29th minute corner struck Anton Ferdinand on the arm, but neither keeper was seriously tested in an untidy first half.
Ferdinand often showed the composure normally associated with his elder brother, Rio, but the central defender limped off just before the interval, Hayden Mullins leaving the bench.
Leeds' supremacy eventually paid off when Aaron Lennon cut in from the right and crossed for Hulse to volley powerfully past Bywater from six yards with the defence asleep.
But the Hammers' first shot on target brought an equaliser. Steve Lomas lofted the ball forward to Teddy Sheringham who chested it down and Williams' deflected shot from 18 yards looped over Neil Sullivan into the net.
Matthew Etherington's free-kick hit a post and the Hammers' luck was out again when Derry skipped through for the late winner.