United midfielder Paul Scholes was sent off in the 85th minute as tempers flared.
The visitors suffered a blow when Rooney limped off the pitch with a gashed leg, after a foul by England team-mate Jamie Carragher.
O’Shea scored the winner in injury-time during a scramble from a free-kicks.