United lost Wayne Rooney through injury and saw Paul Scholes sent off late on for a clash with Xabi Alonso as Liverpool dominated for long spells.
But substitute O’Shea pounced after Liverpool keeper Pepe Reina fumbled Cristiano Ronaldo’s free-kick.
Edwin van der Sar had earlier saved brilliantly from Peter Crouch.
Sir Alex Ferguson celebrated the winner in his own unique fashion on the touchline, and it was easy to see why after his side had somehow fashioned a crucial three points.
Liverpool manager Rafael Benitez resisted the temptation to field an under-strength side ahead of the Champions League meeting with Barcelona at Anfield on Tuesday.
And they had the better of a patchy, and predictably hard-fought, first 45 minutes.
John Arne Riise was within inches of putting Liverpool ahead after 26 minutes, sending a low, driven free-kick narrowly wide.
United escaped again four minutes later when Craig Bellamy robbed the uncertain Nemanja Vidic, but his cross flashed along the six-yard line with Dirk Kuyt unable to apply the final touch.
Liverpool were rarely troubled, although Jamie Carragher had to intervene bravely to deny Rooney as he shaped to shoot inside the area.
The momentum was all with Liverpool as the second half started – and they did everything but score as United were pinned back.
Steven Gerrard shot over from 12 yards, and Bellamy forced a save from Van der Sar low down before having a close-range effort ruled out for offside.
Riise then fired a rising drive just over the top from 25 yards as Liverpool dominated a strangely lack-lustre United.
The game had become a disappointing stalemate, with United replacing an ineffective Henrik Larsson – on his final Premiership appearance before returning to Helsingborg – with Louis Saha.
And United suffered a blow with 18 minutes left when Rooney limped off with a gashed leg and injury to his knee after a high challenge with Carragher.
Saha was at the centre of penalty claims with 12 minutes left when he tumbled under a challenge from Daniel Agger, but referee Martin Atkinson was unmoved.
United then threatened a smash-and-grab when the previously unemployed Reina needed to scoop away a header from Ronaldo.
Scholes and Alonso had been involved in a succession of spats, and the United star saw red after he raised his hand in the direction of the Spanish midfield man though no contact was made.
Van der Sar then produced a pivotal moment, diving acrobatically to his left to palm away Crouch’s shot.
And just as United seemed happy to settle for a point, Reina dropped Ronaldo’s free-kick at the feet of O’Shea, who slammed his finish into the roof of the net.
Liverpool: Reina, Finnan, Carragher, Agger, Riise, Gerrard, Alonso, Sissoko (Crouch 79), Gonzalez (60 Aurelio), Kuyt, Bellamy (Pennant 69).
Subs Not Used: Dudek, Hyypia.
Bookings: Alonso 41, Carragher 72.
Man Utd: Van der Sar, Neville, Ferdinand, Vidic, Evra (Silvestre 63), Ronaldo, Carrick, Scholes, Giggs, Rooney (O’Shea 73), Larsson (Saha 67).
Subs Not Used: Kuszczak, Brown.
Sent off: Scholes 86.
Bookings: Carrick 43, Neville 81.
Goal: O’Shea 90.
Att: 44, 403.
Ref: M Atkinson (West Yorkshire).