Alan Judge came off the bench to blast the Republic of Ireland to victory over the United States, handing John O’Shea the perfect send-off.

The Brentford midfielder’s 90th-minute winner came just seconds after his introduction on a night when Shamrock Rovers striker Graham Burke, the first League of Ireland player to make the starting XI since Joe Gamble in 2007, claimed his first Republic goal to cancel out Bobby Wood’s opener. It clinched a 2-1 win at the Aviva Stadium to ensure O’Shea’s 118-cap international career ended in style.

The home side started on the front foot, with Jonathan Walters forcing a near-post block from DeAndre Yedlin and sending a dipping volley just wide after linking with Burke, who had earlier seen his long-range effort deflected over, inside the opening 11 minutes. However, with Martin O’Neill’s men struggling to turn possession into chances despite the best efforts of Callum O’Dowda and James McClean, who tested keeper Bill Hamid with a swerving 20th-minute strike, the visitors gradually eased their way into the game. They were unfortunate not to go ahead four minutes later when Rubio Rubin attempted to flick Tyler Adams’ fierce shot past keeper Colin Doyle, but he saw the ball loop off the turf and over the bar.

Wood curled a left-footed effort just wide seconds later and Tim Weah had cut in from the right and picked him out, and Doyle had to field Rubin’s skidding shot 11 minutes before the break. It was then that O’Neill ended O’Shea’s evening as planned when he was replaced by debutant Darragh Lenihan, leaving the field to warm applause.

Burke drilled a 41st-minute free-kick into the defensive wall after O’Dowda’s enterprising run had been ended illegally by Yedlin and was hurt when he careered into Cameron Carter-Vickers as he attempted to get to the rebound, although he was able to continue after treatment.

However, it was the Americans who took the lead in first-half stoppage time when defender Matt Miazga climbed above Lenihan and Kevin Long to head Wil Trapp’s free-kick back across goal, where Hamburg striker Wood got between Jeff Hendrick and McClean to stab the ball past Doyle.

The Fiver: sign up and get our daily football email.

The Republic’s ball retention was marginally better as the second half unfolded, but a woeful lack of penetration confounded their attempts to work their way back into the game. But they were back on level terms when Walters recycled O’Dowda’s 57th-minute cross at the far post and Burke stabbed Lenihan’s shot over the line, Ireland’s first goal in 321 minutes of football.

Walters went agonisingly close to a second six minutes later when he stepped outside his man and blasted inches wide, but with the game opening up, Doyle was relieved to see Wood fire straight at him and Weah wastefully over as the visitors responded. However, the Republic got their reward inside the final minute when McClean surged into the box and substitute Judge, who had only been on the pitch a matter of seconds, drilled his shot off the underside of the crossbar to win it.