Mark Noble came off the bench to take a spot kick in the 94th minute following Shaw's handball, but he was unable to rescue a point for his side and Manchester United's unbeaten start to the Premier League season continues.
The sides were level at the break after Ronaldo had cancelled out Benrahma's deflected strike, but Lingard proved the difference in the end as he returned to break Hammers hearts.
Story of the match
Before kick-off a minute's applause was held for Jimmy Greaves, the legendary England international and former West Ham striker who sadly passed away on Sunday at the age of 81. Black armbands were worn by both sides as a tribute to one of the game's greatest ever forwards.
— West Ham United (@WestHam) September 19, 2021
The visitors enjoyed more of the ball during the early stages with West Ham remaining in an organised shape inside their own half, looking well-drilled, as has become the norm under David Moyes in the last couple of seasons.
Despite struggling to get their attack involved, the Hammers had a golden chance with fifteen gone, Said Benrahma robbing Harry Maguire in a dangerous area before feeding Jarrod Bowen, his strike blocked well by Raphael Varane.
The Hammers gained some confidence after going close, and David De Gea was forced into action soon after as Bowen threatened again, the 'keeper saving with his feet to deny a move that involved some flowing intricate passing from the hosts.
The Red Devils began to ramp up the pressure just before the half-hour mark, Fabianski called on again as he made a fantastic save to tip a Bruno Fernandes shot on to the post, then denying a Shaw strike from range moments later.
Despite the pressure, it was the hosts who went ahead with 30 minutes on the clock thanks to a Varane deflection, the Frenchman helpless as he deflected Benrahma's shot past his stranded goalkeeper to make it 1-0.
The opposing French defender, Kurt Zouma, made a great last-ditch block to deny Ronaldo an immediate response, but the West Ham defence was unable to stop the Red Devils' returning hero from equalising minutes later.
The Portuguese drifted in at the far post to meet Fernandes' cross, and converted at the second attempt to make it 1-1. A goal for either side within 5 minutes, and plenty of entertainment for the capacity crowd on a rainy East London afternoon.
Nikola Vlasic made his first Premier League start following his summer arrival, and the Croatian almost had a goal to go with it, but he was unable to keep his effort down after connecting with Cresswell's driven cross and the sides remained level going into half-time.
Man United should have gone ahead within minutes of the restart as they pounced on sloppy passing from the hosts, but West Ham's goalkeeper continued his fine afternoon to deny Ronaldo a second after he was played through by his compatriot.
Pablo Fornals responded with a chance, the game continuing the end-to-end pattern of the first 45, but the Spaniard's flick at goal trickled wide.
David Moyes will have been frustrated by his side's start to the second half as they continued to give away possession cheaply, the visitors maintaining their foothold on the game and searching for a goal to go ahead.
It was evident that both teams had been involved in midweek European action as the tempo of the fixture began to drop, but Solskjaer's men continued to create chances with the Hammers defending deep and waiting for an opportunity to break on the counter.
West Ham were the first to look to the bench as Andriy Yarmolenko replaced Vlasic, and the visitors responded soon after with changes of their own - a return to the London Stadium for Jesse Lingard after his stunning season on-loan last campaign.
Manchester United (@ManUtd) September 19, 2021
There was little goalmouth action in the second-half heading into the closing stages, a half-chance for both Benrahma and Fernandes, and then Fornals fired wide on 80 minutes following a corner.
However, the scenario that all Hammers fans feared came true when Jesse Lingard snatched a win for his boyhood team at the death, firing into the top corner, much to the disappointment of the Claret and Blue faithful that enjoyed watching him play last season.
Despite Lingard's goal, the late drama had not finished there. West Ham won a penalty in the final seconds when Yarmolenko's cross hit Shaw's outstretched arm, and captain Mark Noble came on as a substitute to take the spot kick.
Noble's first touch on the pitch was a tame shot, and United's number one saved well down to his left to ensure United held on, securing another away win.
Decisions, drama, and De Gea heroics as Solskjaer's men return to Manchester with three points. The sides meet again at Old Trafford on Wednesday night for a Carabao Cup encounter.