James Tomkins spared West Ham's blushes with a 90th-minute winner as they laboured to a 1-0 victory over Maltese minnows Birkirkara in the second round of UEFA Europa League qualifying.
It appeared as though Slaven Bilic was going to be left frustrated in what was his first competitive match in charge at Upton Park as Birkirkara goalkeeper Justin Haber put in an excellent display.
However, Haber misjudged a late corner and Tomkins was on hand to give West Ham a slender first-leg lead and allow Bilic to breathe a sigh of relief.
It was harsh on Haber, who made several top saves including tipping Modibo Maiga's effort on the post in one of several chances in a first half dominated by West Ham.
But Tomkins' goal now gives West Ham something to build on for next week's return leg at the Ta'Qali Stadium.
The hosts dominated the early exchanges and Maiga, who saw a tentative third-minute penalty shout for a foul by Nikola Vukanac waved away, should have done better with a tame header over the crossbar from Morgan Amalfitano's cross.
Amalfitano then bent a curling effort just wide of the post, before Haber did well to clamber across goal and keep out Maiga's header when Birkirkara failed to clear an Aaron Cresswell free-kick.
Maiga must have felt the footballing gods were against him in the 27th minute when his fierce 20-yard shot was pushed onto the post by Haber.
West Ham struggled to match that intensity after the break, although Matt Jarvis should have done more to test Haber after jinking his way into the penalty area from the right.
The visitors almost did the unthinkable just short of the hour mark when Ellenton Liliu raced clear and flashed a shot across the face of goal from a tight angle.
Things worsened for Bilic when Kevin Nolan was substituted in the closing stages with an apparent shoulder injury, but West Ham finally got the breakthrough in the last minute.
Haber flapped at Mauro Zarate's corner and Tomkins headed in from close-range to seal a narrow win.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.