United enjoyed slightly the better of a scrappy opening period, and led at the break courtesy of Gayle’s first strike on home soil since December.
Michael Jacobs drew Wigan level with a well-taken effort five minutes into the second half, but – after coming through a spell of pressure unscathed – Ritchie restored the Magpies’ lead in front of the Gallowgate End.
The Latics never quite looked dead and buried, but Graham Barrow’s strugglers were unable to find another equaliser, meaning the Magpies remain top of the Sky Bet Championship heading into Wednesday’s visit of Burton Albion.
Though Wigan started promisingly – enjoying as much of the ball as United early on – they were twice grateful to defender Jake Buxton, who produced two important blocks in the opening quarter of an hour.
Just two minutes in, Jonjo Shelvey received Vurnon Anita’s pass and carried the ball towards the edge of the penalty area, but Buxton flung himself in the way of the midfielder’s effort.
Shelvey then worked the ball wide to Ritchie, who stepped back inside before seeing a vicious attempt diverted clear by the Wigan centre-half.
There was a moment of concern for United to withstand at the other end, as Shaun MacDonald nodded Jamie Hanson’s corner into the path of Dan Burn. However, Karl Darlow managed to gather the defender’s low-struck effort.
Shelvey then directed an Anita cross wide of the target from 12 yards, before Gayle was denied by Matt Gilks after meeting Grant Hanley’s flick-on at the back post.
But, Wigan were powerless to stop Gayle just five minutes later.
Diame collected Anita’s pass and put the ball on a plate for the Magpies’ leading marksman, who registered his 22nd goal of the season from deep inside the area.
Gayle almost added a second before the break. Following a quick counter, the frontman latched onto Shelvey’s ball through the middle, but the backtracking McDonald got back in time to block.
Omar Bogle brought a two-handed stop out of Darlow with the last action of the first half, having just done enough to shake off the challenge of Grant Hanley.
But, just five minutes after the break, parity was restored.
The ball broke kindly for Jacobs on the edge of the penalty area, though there was nothing fortunate about the midfielder’s finish – a delicate chip over Darlow after the ‘keeper looked to close the angle.
The Latics should have completed the turnaround two minutes later, as towering defender Burn met Jacobs’ set-piece unchallenged, only to head high of the target.
Substitute Ryan Colclough then sent a cross-come-shot agonisingly wide of the far post as Wigan enjoyed something of a purple patch.
Before the hour-mark, though, the visitors found themselves trailing again.
After Yoan Gouffran just failed to get his shot away, the ball rolled into the path of Ritchie, whose stinging drive was turned onto the post by Gilks. However, the winger was the quickest to the follow-up, nodding the ball back across goal and into the net.
Still, Wigan continued to probe, and with 20 minutes remaining, Darlow did well to turn Colcough’s thunderbolt out for a corner.
The lively Colclough then took aim again, cutting in from the left flank before sending a dipping effort just off-target.
Tensions flared among the two teams’ coaching staff late on, after Ritchie saw his appeals for a penalty waved away after taking a tumble in the box.
It was to matter little in the end, though, as Newcastle saw out three minutes of additional time to pick up a first win at St. James’ Park since February.