Premier League West Ham were forced into a penalty shoot-out by Birkirkara before eventually progressing in the UEFA Europa League.
West Ham scraped through their UEFA Europa League second qualifying round tie with Birkirkara 5-3 on penalties following a shock 1-0 defeat on the night in the second leg.
The Premier League side led 1-0 from the initial encounter at Upton Park following James Tomkins' last-gasp winner in that game, but the tie was quickly levelled as Birkirkara produced a fine first-half showing on Thursday.
Former Juventus striker Fabrizio Miccoli opened the scoring with a close-range strike, before West Ham were reduced to 10 men as Tomkins was sent off for an off-the-ball incident.
In energy-sapping conditions, West Ham's toil for a decisive goal in regulation time proved fruitless, and still they could not make the breakthrough in extra time, even after the Maltese side also had a man sent from the field when Mauricio Mazzetti picked up a second booking.
But Slaven Bilic's men unsurprisingly displayed the greater composure from the penalty spot, with Diego Poyet sending them through after Nikola Vukanac had missed for Birkirkara.
West Ham's next opponents are Astra of Romania, who knocked out Scottish side Inverness Caledonian Thistle 1-0 on aggregate.
Miccoli stunned the Premier League side with the opener from the game's first real chance in the 15th minute.
The veteran slid in at the near post to divert to turn the ball home following great work down the right from Liliu, sparking jubilant scenes among the home fans at the Ta'Qali National Stadium.
West Ham dominated possession in search of an equaliser but struggled to find a way through a stubborn Birkirkara defence.
And Tomkins' frustration with the situation boiled over just before half-time as he flung Vukanac to the ground in an off-the-ball tussle as he prepared to attack a right-wing free-kick.
Following vehement protests from both sides, referee Enea Jorgji eventually showed Tomkins a straight red card, with Vukanac receiving a booking.
Bilic threw on Poyet and Modibo Maiga for Kevin Nolan and Morgan Amalfitano early in the second half in a bid to give his depleted side some fresh legs in the heat.
But West Ham still found it difficult to fashion clear-cut chances, although Matt Jarvis' cross-cum-shot forced Birkirkara goalkeeper Justin Haber into action.
The visitors could not prevent extra time, despite Birkirkara appearing to tire significantly in the closing stages.
Jarvis saw an effort deflected wide in the 94th minute and West Ham then received a welcome boost when Mazzetti became the second player to be dismissed.
The defender was given his marching orders as he received a second yellow card for apparent dissent after a free-kick was awarded in the opposition's favour.
West Ham looked to have found the all-important goal in the 117th minute when Maiga slotted home, only for the Malian to be denied by the offside flag.
However, West Ham's blushes were finally spared in the shoot-out as Vukanac's penalty that cleared the crossbar proved decisive.