Both sides produced some excellent rugby in a see-saw encounter that featured 14 tries, a sending off and some shuddering defence.
Chester, who gave debuts to Rob Nixon and Dave Lenton, fell behind on 11 minutes when Wigan scored the game's opening try but the Gladiators hit back strongly.
Steve Threlfall got Chester off the mark on 20 minutes as he finished off an outstanding passage of play that saw Dan Rowett spring out of dummy half before exchanging passes with Andy Hill and setting up Threlfall.
Prop Michael Durham, whose strong running troubled Wigan througout, then barged his way over the visitors line four minutes later to put the Gladiators in front.
However, the Riversiders responded with two converted tries in quick succession before the interval to take a 16-10 lead into the break.
Chester started the second period strongly and prop Chris Young crashed over the line on 45 minutes to level the scores at 16 all. But the Gladiators joy was shortlived as Wigan regathered the short kick-off before touching down for a try to regain the lead.
The Riversiders extended their advantage with a try on 56 minutes to take a 28-16 lead as the momentum looked to have swung in the visitors favour but Chester refused to buckle and once again hit back in style.
Damon Williams waltzed his way past a couple of defenders after linking up with Chris Pape to score on 63 minutes and Pape then dummied his way over for his first try of the season to level the score.
With ten minutes left on the clock both sides sensed victory and it was Wigan who drew first blood as they squeezed into the corner for a try to recapture the lead.
Chester thought Young had scored his second try of the game on 74 minutes but the referee ruled he had failed to ground the ball and Wigan rubbed salt in the Gladiators wounds by racing 60 metres for what appeared to be a match winning try.
But a determined Gladiators outfit refused to lie down and poured forward in search of the six points needed to tie the scores. They shifted the ball to the left in an attempt to find an opening and centre Lenton spotted a gap to slide in for a vital try and Simon Quinn's conversion leveled the scoreline at 38-38 with two minutes left.
With time running out, a draw seemed the likely outcome but a handling error deep inside Wigan territory presented Chester with one final chance of snathcing the win.
The Riversiders defence repelled two strong drives before veteran Foster twisted and turned his way past two tacklers to touch down for the deciding score with just seconds remaining.
Gladiators fullback Simon Quinn was named as the Bartletts Solicitors man of the match ahead of the excellent Steve Threlfall and try scoring hero Foster, although every player contributed to an outstanding team performance.