This was a smash-and-grab victory that keeps Manchester United in the hunt for a top-four finish. They were hardly pretty but will not care given the business end of the season requires wins and wins only. Paul Pogba was the saviour as he scored two penalties, creating the latter with a ball into Anthony Martial, as Ole Gunnar Solskjær’s team secured all three points with only 10 minutes left.

Both United’s penalties were dubious, though, as was the decision to rule out a Felipe Anderson effort for offside when the game was scoreless.

With Luke Shaw and Ashley Young suspended and Tuesday night’s Champions League quarter-final second leg at Barcelona in mind, changes for United were inevitable. Of the starters in Wednesday’s 1-0 first-leg defeat here, six survived as in came Phil Jones, Marcos Rojo, Juan Mata, Martial and Jesse Lingard.

Manuel Pellegrini’s side had three changes from the XI that began Monday’s 2-0 defeat at Chelsea, with Pablo Zabaleta, Robert Snodgrass and Arthur Masuaku brought in. Marko Arnautovic was the most notable absentee, through illness.

There was an open start to a half that continued throughout. Felipe Anderson’s “illegal” goal came when he finished beyond David de Gea but the strike was ruled offside despite Diogo Dalot appearing to have kept him onside.

West Ham were enjoying space between the United defence and midfield and along the flanks. Still, there was the same freedom to play for the home side and, when Fred utilised this to move his team forward, Mata was dumped over by Snodgrass and the referee, Graham Scott, pointed to the spot despite the Spaniard perhaps being outside the area and contact possibly fair. Up trotted Pogba to hammer home a 15th goal of the season.

West Ham attempted an instant response but Manuel Lanzini’s free-kick went for a corner and, when a second followed, Anderson’s glancing header bounced wide.

The end-to-end stuff continued, Romelu Lukaku leading a charge to West Ham’s area that had Pogba, Martial and Mata following. This move eventually broke down due to offside. Dalot was next to threaten but the right-back’s shot went wide.

Solskjær, whose side began the game in sixth, had said attaining a Champions League berth was a challenge and given how average United were throughout this first half it felt an understatement. After Lukaku’s shot was deflected for a corner Chris Smalling’s subsequent header was as misdirected as Rojo’s attempted clearance at the other end a few moments later.

United ended the period hanging on, with De Gea having to clear an Anderson effort off his line with a boot.

Paul Pogba fires home his, and Manchester United’s, second goal of the game. Photograph: Simon Stacpoole/Offside/Getty Images

Declan Rice showed first after the break, West Ham’s holding player surging down the right, and he was about to help create an equaliser that began and ended with a De Gea error, four minutes into the second half.

The Spaniard’s loose throw was meant for Pogba but found only Rice. He passed to Snodgrass, who moved the ball to Lanzini. The No 10’s cross from the left went right across goal to Felipe Anderson and his close-range attempt was allowed to squeeze in at the near post, thanks to De Gea’s poor attempt at a save.

Manchester United were stunned and West Ham were in the ascendancy. Solskjær reacted quickly by replacing Mata with Marcus Rashford.

The reshuffle had Lukaku fanning out right and Rashford becoming centre-forward. There was nearly an instant dividend. Smalling played Rashford in along a right-hand channel and his shot was parried by Lukasz Fabianski, West Ham’s keeper.

This signalled an upturn in urgency and energy and Rashford really should have restored the home side’s lead with a close-ranger header seconds later. United were camped in West Ham’s defensive third but unable to dominate, with Rojo the chief culprit in a rearguard in disarray when the Hammers attacked.

Both managers made changes. With 14 minutes left Rojo and Lukaku made way for Andreas Pereira and Mason Greenwood. Yet it was Michail Antonio, introduced by Pellegrini just beforehand in place of Javier Hernández, who was soon crashing a shot off the bar before De Gea had to produce a fine save from his header.

But Ryan Fredericks, who had come on for Zabaleta, then brought down Martial and Pogba again did the business from the spot – Pellegrini later claimed Rashford, from an offside position, touched the through ball on but by then it was too late.