Sam Allardyce's side, who ended the game with 10 men, thought they had done enough to secure at least a point as Ravel Morrison and Mark Noble netted their first Premier League goals since the opening day of the season.
The Hammers had gone more than five hours of top-flight football without finding the target before edging ahead against the Toffees.
They survived an early scare when Kevin Mirallas forced Jussi Jaaskelainen into a fine sprawling stop, but broke the deadlock on 31 minutes when Matt Jarvis teed up Morrison on the edge of the box and his drilled effort took a wicked deflection off Phil Jagielka to leave Tim Howard wrong-footed.
Lukaku came on for his Everton bow as part of a double change at the interval, and Roberto Martinez was forced to play his final card within seven minutes of the re-start as Leon Osman hobbled from the field.
Fresh faces appeared to breathe new life into the visitors and they had been knocking on the door for some time before hauling themselves level in spectacular fashion just past the hour mark, with Baines crashing a trademark 25-yard free-kick into the top corner.
It was, however, to be the hosts who got their noses back in front, with Noble stepping up on 76 minutes to calmly convert from the penalty spot after Kevin Nolan had been tripped inside the box by James McCarthy.
The West Ham midfielder went from hero to villain in the space of five minutes, though, as he collected a second yellow card for a foul on Ross Barkley and saw Baines bend another fabulous free-kick into the back of the net off the inside of the post.
With the Hammers rocking, Everton rammed home their numerical advantage five minutes from time when Mirallas floated over a cross and Lukaku bravely powered a header past Jaaskelainen - with a nasty clash of heads suggesting he may not remember too much about his dramatic clincher.
West Ham - missing attacking options Andy Carroll, Joe Cole and Stewart Downing to injury - can take comfort from the end of their scoring drought which had lasted 314 minutes until Morrison fired them ahead after half an hour.
Everton went close after six minutes when Mirallas tested Jaaskelainen and Steven Naismith was inches away from a second attempt when the ball sailed past.
It was West Ham, though, who showed precision in the 31st minute as they surged ahead, although a large deflection off Jagielka helped them to take the lead.
Jarvis, once again proving a handful down the left wing, skillfully threaded his way infield and teed up Morrison and the former Manchester United midfielder drilled the ball home.
Lukaku came on for the second half and his delicate early touch was taken on by compatriot Mirallas, who raced to the byline and crossed only for West Ham to recover by getting numbers back.
Naismith had also made way for McCarthy as Martinez attempted to invigorate his side, but the Hammers were more creative with Jarvis galloping free and just failing to find Modibo Maiga.
Showing vision once more, Lukaku played Barkley into the area only for the England midfielder to run down a blind alley.
The initiative had been seized and in the 62nd minute the equaliser arrived, Baines steering a terrific 20-yard free-kick beyond Jaaskelainen into the top left corner.
Noble flashed a corner wide of the left post and Baines forced a save from close range as the match opened up.
Noble powered home from the spot after Nolan had been hacked down by McCarthy, but then he trudged off after receiving a second yellow from referee Lee Mason and Baines delivered the equaliser.
The outstanding Lukaku deserved a goal and it duly arrived as he nodded Everton to victory.