Latics had led 2-0 at the break thanks to goals from Will Keane and Stephen Humphrys.
With Tom Naylor hitting the bar, and Keane striking a post and seeing another effort miraculously headed off the line, Gillingham were hugely fortunate to still be in the game.
And they took full advantage of their hosts' profligacy, with Ben Reeves and Stuart O'Keefe restoring parity by the 70-minute mark.
Wigan, though, have scored more late goals than any other side in the EFL, and took the spoils - and leadership of the division - when Keane notched his 15th goal of the campaign with 13 minutes remaining.
"I thought we were excellent in the first half," said Richardson. "If you would have one criticism, it's that we didn't score more goals.
"We always expected a reaction from Gillingham, and they kept us honest all the way through.
"The goals are disappointing from our point of view - the first one was down to us, the second one was down to the officials - albeit a genuine mistake.
"Being respectful to Gillingham, I thought they showed loads of fight, loads of endeavour, and we had to stand up to that.
"Thankfully, we've managed to come back at the end, we've created a couple of chances and then got the goal from the set-piece.
"You've just got to keep believing in what you're doing, and that's what we do.
"It's all about repetition and, as long as people are on the same page, if you keep doing the right things and keep working hard, hopefully you'll get that bit of luck you always need.
"We've certainly got the quality of players on the pitch to create those chances, and thankfully we were able to take them again."
Get 20% off our sports subscription package and stay up to date with all the latest Wigan Athletic news with a year’s subscription to WiganToday for less than 9p a day. Use promo code TRANSFER20