It had been a one sided affair until Roberts' second half strike put the Dragons on their way but Town were still confident of a result until Stephen Thomas' thundering free kick finally deflated the lacklustre Terriers.
Wrexham were a useful side but Town were expected to win this match and they set about that task with aplomb after a steady start.
Andy Dibble hurt himself after just 7 minutes of play while clearing the ball and had to be replaced by rookie 'keeper Paul Whitfield.
Whitfield did his job well, however, and kept out an early chance by Chris Holland, who had ghosted into the box on 10 minutes, after the Town midfielder was put through by a Jon Stead flicked header.
Whitfield kept his nerve and parried the strike.
Town had a steady supply of chances as the first half unfolded.
Kevin Sharp and Martin Smith combined down the left to lay on a pristine chance for Jon Stead to open the scoring after 14 minutes but the youngster contrived to hammer the ball over the bar.
John Thorrington and Simon Baldry attacked effectively down the right and Thorrington tested Whitfield with an effort which the rookie tipped away for a corner.
Martin Smith had plenty of practice with his right sided corner deliveries in the first half, with Whitfield concentrating hard to deny Town chances from the multiple set pieces that came his way.
Chances for the Dragons were few but Lee Trundle's pass for Stephen Thomas in the 21st minute deserved a goal but Scott Bevan used all of his 6'6" height to palm away the tricky effort.
Darren Ferguson had been the focus of many good things from Wrexham and
Dan Bennett was almost the gleeful recipient of a chance served up by playmaker Ferguson but he couldn't keep his effort on target.
The home side had chances in the second half when Nat Brown gave the ball away early on but Scott Bevan rescued the blushes of the young central defender when he saved Paul Barrett's shot.
Town were getting complacent, with mistakes creeping into their defensive play, and paid for their overconfidence with stunning goal scored by Steve Roberts in the 64th minute.
Shaun Holmes forced Scott Bevan into a save to concede a corner from which Darren Ferguson curled a superb set piece onto the boot of the advancing Steve Roberts who unleashed a stinging left footed volley that defeated Bevan and put them into the lead.
With Town in disarray, Wrexham had the chance to go 2-0 up with a little over 20 minutes to go but Lee Jones chested the ball down with Scott Bevan in attendance but couldn't get his shot on target.
After a tactical re-shuffle to 4-4-2 Dwayne Mattis levelled matters in the 75th minute when he dribbled past a clutch of defenders and finally defeated the resolute Whitfield with an fine solo goal and the stage seemed set for the recovery as a re-shaped Town looked for the winner.
Martin Smith had two great chances to win the match late in the game but he couldn't find the target with two superb lay-offs forced by Danny Schofield, the second was struck sweetly against the crossbar in the 82nd minute as Town fans agonised with time running out.
Golden Goal extra time was on the cards until Wrexham pulled off their shock victory with another set piece.
Stephen Thomas won the game for the home side when Nat Brown gave away a dangerous looking free kick in the D in the 88th minute and the Dragons man fired off a rising free kick which flew over the wall and went in off the underside of the bar with Scott Bevan and the Town defenders looking on stunned.
Bevan went upfield for a last gasp chance of a goal at the death but to no avail.
Town (4-3-3): Bevan, Sharp, Brown, Moses, Heary, Holland, Mattis, Baldry (Irons 84), Thorrington (Scofield 64), Smith, Stead
Subs: P Senior, Schofield, Irons, McDonald, Dyson
Booked: Brown (pushed Trundle 88)
Goal: Mattis 74
Wrexham (4-4-2): Dibble (Whitfield 6), Whitley, Holmes, Roberts, Jones (Sam 75), Trundle, Ferguson, Barrett, Bennett, Pejic, Thomas
Subs: Carey, Edwards, Whitfield, Sam, Spender
Goals: Roberts 64, Thomas 88
Referee: Andy Penn (West Midlands)
Attendance: 1350 (approx 150 away fans)
Read Mel Booth's full report in the Examiner on Wednesday.