West Ham had the better of the first-half openings without managing to find a way past Huddersfield, who headed into the match without conceding in their opening three league fixtures.
Cheikhou Kouyate could not quite turn the ball in with three minutes on the clock following a blasted cross from Andy Carroll, who was making his first outing of the campaign as one of five United changes.
Javier Hernandez was next to come close, hitting the crossbar from 10 yards out after some impressive play from the lively Michail Antonio, before Carroll had a deflected shot easily collected by Lossl in the opposition goal.
The Irons had seven corner kicks in the opening 45 minutes but did not truly make the most of them, with James Collins awkwardly heading the ball at Lossl from the best of the bunch.
A big opening also came and went for Kouyate who, soon after seeing a weak penalty shout rejected, scuffed the ball horribly wide when getting on the end of a loose ball just inside the area.
Kouyate then fluffed his lines once again when picked out by Hernandez, which sparked under-fire United boss Bilic into action as he brought on Ayew for the Mexican striker - a change not well received by home supporters.
After seeing a couple of dangerous Aaron Cresswell deliveries come and go, the Terriers' resistance finally broke as they shipped for the first time in 342 Premier League minutes.
It took a huge slice of luck for the hosts to find a way through, with Obiang's shot taking a big deflection off Mathias Jorgensen on its way past a wrong-footed Lossl.
That proved to be a huge moment in the game as Ayew scrambled home the second from close range five minutes later after a corner was not dealt with by Huddersfield.
Tom Ince almost pulled one back late on, seeing his deflected shot come back off the bar as West Ham held out for victory in their first home game of the campaign.