The 37-year-old, who will now retire from international football, left the field to a standing ovation in the 35th minute as his lengthy Ireland career came to an end.
USA took the lead through Bobby Wood after O'Shea's exit, but Ireland came from behind to win as Graham Burke scored his first international goal before Alan Judge netted a last-minute winner to end Ireland's three-match losing streak.
O'Shea almost got his night off to the perfect start after just eight minutes when he went up for a corner, only to glance his header wide of the target.
Ireland continued to be the early aggressors, though, and Jonathan Walters flashed one effort narrowly wide before Bill Hamid was forced into his first meaningful save of the night to deny James McClean.
USA eventually settled and began to grow into the game, and they threatened twice in quick succession when first Tyler Adams and then Wood failed to hit the target midway through the first half.
O'Shea's final departure in an Ireland shirt came shortly after the half-hour mark, and his exit - the last of the 100-cap players who have been stalwarts of the Irish squad over the past decade and more - heralded the beginning of a new era too, with Darragh Lenihan replacing him for his first cap.
The fond farewell disrupted the rhythm of the match, though, and it wasn't until the stroke of half time that either side had another clear chance when Seamus Coleman failed to make the most of a handling error from Hamid.
USA may have been happy to go into the break still goalless, but things got even better for the visitors in first-half stoppage time when Matt Miazga's looping header found it way to Wood, who tapped it home to give his side the lead against the run of play.
Ireland were level before the hour mark, though, and Burke was left celebrating his first international goal on just his second appearance, getting the final touch to Kevin Long's effort, which would have crossed the line anyway.
Wood and Weah both then came close in quick succession for the visitors before Lenihan had the ball in the back of the net for Ireland, only to see his header ruled out for offside.
The match eventually calmed down again as a string of substitutions took their toll, although Martin O'Neill saved his best until last when he brought Judge on in the 89th minute.
Less than two minutes later the Brentford man was celebrating the winning goal - and his first for Ireland - when he beat the offside trap before curling his finish into the top corner at the end of a slick team move.
There was no time for a response for USA as Ireland held out for their first win since October, whereas USA - who will be absent from a World Cup for the first time since 1986 this summer - see their two-game winning run come to an end.
REPUBLIC OF IRELAND (3-5-2): Doyle; Duffy (Stevens 77'), O'Shea (Lenihan 35'), Long; Coleman, Hendrick (Arter 83'), Rice, O'Dowda (Judge 89'), McClean; Burke (Horgan 58'), Walters
USA (4-1-4-1): Hamid; Yedlin (Moore 70'), Carter-Vickers (Parker 61'), Miazga, Villafana; Trapp; Weah, Adams, McKennie (Corona 81'), Rubin (De la Torre 77'); Wood (Sargent 70')