Swansea said farewell to the Vetch in style by adding their first FAW Premier Cup trophy to League One promotion.
Striker Juan Ugarte gave Wrexham the lead, firing home after Dennis Lawrence freed him with a run to the by-line.
But ex-Wrexham man Lee Trundle inspired a comeback, his attempted cross headed in by Shaun Pejic for a cruel own goal.
Trundle then controlled a long ball and freed substitute Andy Robinson, whose powerful left-foot volley won the game and sparked wild celebrations.
While this was Swansea's first win in three finals, it denied Wrexham a third successive title and a sixth overall.
It completed a miserable season for the in-administration Dragons, who have been relegated from League One and who still fear for their very existence next season.
But nothing could dampen the enthusiasm of a 9,000-strong Swansea crowd, witnessing the final game at the Vetch before the 93-year-old ground is demolished, with the club moving to the new stadium in Morfa next season.
Wrexham, benefiting from the experience of playing in a higher league, showed the superior team-work early on, and chances fell to Andy Holt, Chris Llewellyn and Ugarte.
But the home side gradually worked their way into the game, Izzy Iriekpen and Paul Connor missing free headers shortly before the break.
Connor threatened again at the start of the second period, firing in a great shot from outside the area that was well parried by Wrexham goalkeeper Ben Foster.
The Dragons came straight back, Llewellyn and Lawrence forcing fine saves from Swans stopper Willy Gueret.
A towering Lawrence header was cleared off the line by Ijah Anderson, and it was the Wrexham man who created the opening goal.
Some sloppy defending allowed Lawrence to get to the by-line before pulling the ball back past Gueret to Ugarte, the Basque striker finishing confidently from the centre of the penalty box.
Swansea were struggling to create openings until Trundle went on a run into the Wrexham box and aimed a cross at Connor.
Dragons defender Pejic came piling across to clear, but could only head powerfully past a helpless Foster for the equaliser.
With 15 minutes remaining, a long Gueret clearance was brought down by Trundle.
The striker freed Robinson who controlled his volley superbly to beat Foster.
Wrexham kept battling and Gueret saved well from a well-worked Llewellyn strike, as the Swans fans tried to pre-empt the game's end by edging onto the hallowed Vetch turf.
Come the final whistle nothing could hold them back as the famous old ground was plundered for souvenirs of a memorable night - and a memorable history.
Swansea: Gueret, Austin, O'Leary, Tate, Martinez, Britton, Anderson, Iriekpen, Connor, Forbes, Trundle.
Subs: Murphy, Robinson, Gurney, Thorpe, Bond.
Wrexham: Foster, Pejic, Morgan, Lawrence, Edwards, Holt, Mark Jones, Williams, Crowell, Llewellyn, Ugarte.
Subs: Michael Jones, Smith, Bennett, Green, Sam.
Referee: B Lawlor (Wales)