West Ham scraped through their 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.