Spanish striker Juan Ugarte hit a superb hat-trick to put Wrexham within touching distance of the LDV Vans Trophy final.
The deadly Ugarte punished Oldham for a dire performance at the back and his side must lose the northern final second leg by three goals in order to be denied their place in the national final.
The clash at Boundary Park started quietly but Ugate brought it bursting into life when he broke the deadlock on 28 minutes. A goal feast followed and Mark Jones and Darren Ferguson also netted for Wrexham with Scott Vernon hitting back twice for the home side.
Ugarte's opener came after Mark Jones burst into the box and brought a save from Oldham's Australian keeper Leslie Pogliacomi.
The ball broke free and Ugarte was first to react as he slammed it into the empty net from six yards. Wrexham were soon two ahead as Jones beat two defenders inside the box and rifled in a low shot which gave Pogliacomi no chance.
Oldham replied on 35 minutes as Vernon worked some space 18 yards out before sending a shot into the bottom corner via goalkeeper Ben Foster's outstretched right arm.
Oldham wasted chances to draw level and paid the price when Ugarte seized on a defensive error to slot in from close range.
Wrexham made it 4-1 when skipper Ferguson hit a 25-yard free kick, which seemed to wrongfoot Pogliacomi.
And Ugarte finished off his hat-trick when he raced onto a long ball over the top and calmly dispatched it from 14 yards as Pogliacomi dashed off his line.
Oldham were down and out but sub David Eyres cracked in a left-foot shot from 12 yards which beat Foster after hitting the inside of the post.
Eyres also had a goal disallowed before Kevin Betsy was brought down in the box by Craig Morgan and Vernon stepped up to convert the penalty.