Wing-back Paudie Foley was the hero for Wexford as he landed a point in the fourth minute of injury-time to capture the Walsh Cup at O’Moore Park in Portlaoise.
Galway looked set to retain the title when they led by four points with five minutes to go but Davy Fitzgerald’s side rallied.
A pointed free from Seamus Casey got the gap back to three points and then Cathal Dunbar levelled with a goal two minutes into stoppage time.
Wexford pushed on from there and Foley, after seeing a long-range free drop inches short, made no mistake with the winner which he landed from 60 yards on the right wing.
The sides were level five times in the opening half but Galway scored the last three points before the break to lead by 0-10 to 0-8 in front of a crowd of 1,725.
Tadhg Haran led the way with seven points from frees, while at the other end Jack O’Connor hit five from placed balls in response.
The sides exchanged points three times in the opening nine minutes before Wexford pulled away with four in a row, two of them frees from O’Connor with Damien Reck and Aidan Rochford also hitting the target to lead by 0-7 to 0-3 after 15 minutes.
Galway, who hit eight wides to Wexford’s two in the opening half, responded with three more frees from Haran while Ja Mannion was their only forward to score from play in the first-half when he hit the target after 22 minutes.
Midfielder Rochford edged Wexford back in front after 29 minutes with his second point but Galway finished the half strongly and Haran tacked on three more frees to lead by two at the interval.
Two more frees from Haran and a couple of good efforts from play from Adrian Tuohy and Brian Concannon pushed Galway 0-14 to 0-8 in front before O’Connor reduced the margin with three frees in succession to leave a goal between after 50 minutes.
Haran pushed that out to four with his first point from play and then landed his tenth free to lead by 0-16 to 0-11 after 55 minutes.
Wexford got the gap back to a goal in the closing stages thanks to a couple of frees from Seamus Casey and then a goal from Conor McDonald levelled two minutes into injury-time before Foley landed his last gasp winner.
J Lawlor; G Molloy, L Ryan, J O’Connor; P Foley 0-1, R Donohoe, D Reck 0-1; A Rochford 0-2, K Foley; J O’Connor 0-8 (8f), A Nolan 0-1, C McDonald 1-0; H Kehoe, A Shore, M Dwyer.
Liam Og McGovern for Shore (41), Paul Morris for Kehoe (41), Shaun Murphy for D Reck (41), Simon Donohoe for R Donohoe (47), Cathal Dunbar 0-1 for Dwyer (49), Seamus Casey 0-2 (2f) for Jack O’Connor (57).
D Fahy; TJ Brennan, P Killeen, J Grealish; P Mannion, G McInerney; A Tuohy 0-1; S Linnane 0-1, S Loftus 0-1; T Haran 0-12 (11f), C Walsh, B Concannon 0-1; J Mannion 0-1, J Flynn, E Niland.
Aidan Harte for McInerney (half-time), Davy Glennon for Linnane (50), Diarmuid Kilcommins for Concannon (50), Thomas Monaghan 0-1 for Walsh (52), Ronan Burke for Brennan (55), Niall Burke for Flynn (57), Concannon for Loftus (67), Brennan for Haran (70).
M Murtagh (Westmeath).