Flynn won possession in the box and poked past the goalkeeper to win the game for Stephen Robinson’s men who record back-to-back victories.
Freddie Ladapo had equalised earlier in the second half after Cody McDonald gave Gillingham a first half lead.
The victory is what the manager and his players deserved after a strong second half display and that moves Latics off the bottom of the Sky Bet League One table.
Manager Stephen Robinson named an unchanged side from Tuesday night’s victory over Fleetwood Town meaning Carl Winchester kept his place and made his first league start of the season.
It would be Gillingham who started the better of the two sides and took the lead on 10 minutes through McDonald.
Bradley Dack’s corner into the box found the striker at the back post and he nodded into the back of the net, despite the best efforts from Cameron Burgess.
Robinson’s men responded well to going a goal behind and knocked the ball around well.
Gillingham’s Scott Wagstaff went into the book on 19 minutes for clipping Ryan Flynn’s heels as he attempted to break with the ball.
Paul Green almost set Lee Erwin through on goal midway through the half but Max Ehmer quickly got across to intercept the through ball.
However, minutes later, Gillingham almost extended their lead minutes later as Paul Konchesky crossed into the box to find McDonald but he headed straight at Connor Ripley.
After Dack again tested the palms of Ripley, Billy Mckay had Athletic’s first effort on goal, forcing a smart save from Stuart Nelson from 25 yards.
Green was the next Latics player to go close after a smart corner routine found the midfielder in acres of space, he shot but his effort was deflected for a corner.
Winchester’s set pieces were causing a problem for the Gills defence as they were forced to concede four corners in a row.
From one of the corners, the ball found Green on the left, his inswinging cross was towards Burgess in the centre but out of nowhere, a Gills defender managed to head behind.
Peter Clarke met Winchester’s fourth corner into the box and really should have done better when given space in the centre but his effort went wide of Nelson’s goal.
Dack was booked before half time for a late challenge on Fane as Latics went into the break a goal behind.
Athletic started the second half much the better side and will have wondered how they weren’t level on two occasions.
Flynn’s excellent through ball found Brian Wilson who got behind the defence, he crossed low to Erwin at the back post but with the goal gaping, he shot wide.
Latics had the momentum and two minutes later Flynn’s cross was flashed across the six yard box to Jamie Reckord but the full back could not connect from close range.
Robinson brought on Lee Croft and Ladapo on the hour mark as Latics looked to make their pressure pay.
That move proved to be an inspired one from the manager as Ladapo equalised on 65 minutes.
Flynn played the ball to the right of Ladapo who held off his man excellently and smashed the ball past the goalkeeper to grab a deserved leveller.
The striker was subsequently booked for his celebration after going over to the 127 Oldham Athletic supporters
From that moment on it was all Latics. Flynn went close minutes after the equaliser whilst he turned provider again for Ladapo but Stuart Nelson was out to deny the striker.
Flynn was making a massive impact on the game as he took the ball past three men before forcing a smart save from Nelson.
Captain Clarke met a corner into the box from Croft as Latics pushed and pushed for a winner in the game.
Athletic found themselves scratching their heads how they did not take the lead twice in the final five minutes of the game.
Firstly Flynn crossed to Ladapo who could not reach the ball whilst on 88 minutes the Crystal Palace loanee scuffed an effort from five yards as Latics felt their chance had passed.
However, with Robinson’s men picking holes in the Gills defence, they made their pressure pay in the final minute of the game as Flynn grabbed a deserved winner.
The midfielder won the ball in the penalty area and he had the coolest head in the stadium, prodding past the goalkeeper to win the game for Robinson’s men.
That goal knocked the stuffing out of Gillingham and Latics kept the ball comfortably and saw the game out to win a pulsating encounter.
Gillingham: Nelson, Herd (Jackson 68’), Ehmer, Oshilaja, Wagstaff (Byrne 81’), Hessenthaler, MacDonald, Konchesky, Dack (Osadebe 66’), Wright, Nouble.
Subs not used: Hadler, Pask, Oldaker, List.
Oldham Athletic: Ripley, Wilson, Clarke, Burgess, Reckord, Winchester (Croft 59’), Fane, Green, Flynn, Mckay (Ladapo 61’), Erwin (Banks 90+2’).
Subs not used: Kettings, Law, Klok, Osei.
Goals: Gillingham (McDonald 10’) 1-2 Oldham Athletic (Ladapo 65’, Flynn 89’)
Attendance: 6,425 (127 visiting supporters)