The Magpies had dropped into the relegation zone courtesy of Huddersfield Town's 4-1 victory over Bournemouth earlier in the day, but Ritchie's well-taken effort gave Rafael Benitez's side their first league victory in the North-East since October 21 and moved the club into 13th place in the standings.
Moments later, Ayoze Perez hooked a 25-yarder marginally off target and it took until after the quarter-hour mark for the visitors to apply any kind of pressure on the Newcastle goal.
The match slowly began to open up with Kenedy warming the hands of De Gea from distance before at the other end, Newcastle goalkeeper Dubravka - making his debut - was able to divert Jesse Lingard's bobbling effort wide of the post.
Man United were beginning to get on top and twice in the space of six minutes, Anthony Martial squandered opportunities, with a glancing header wide of the far post following Dubravka's excellent block to prevent the Frenchman from netting from eight yards.
After the restart, Man United went onto the front foot, with Alexis Sanchez unfortunate not to open the scoring when his shot from 10 yards was deflected into the side-netting after he had taken the ball past both Shelvey and DeAndre Yedlin.
Sanchez then appeared destined to score when latching onto a Romelu Lukaku pass and taking the ball past Dubravka, but Florian Lejeune got back to prevent the January signing's effort from finding the empty net.
However, Newcastle always remained a threat at the other end and after the Magpies were awarded a free kick on the halfway line due to simulation from Smalling, they went in front.
The set piece was floated into the area and after Gayle capitalised on a knockdown, the striker flicked the ball into the path of Ritchie who drilled a shot into the bottom corner from 12 yards after being left on his own by the penalty spot.
The visitors almost netted an immediate equaliser only for Ashley Young's driven effort to be well saved by Dubravka, but the opportunity acted as the catalyst for United to dominate the closing stages.
Martial remained in the thick of the action and he twice should have netted when the ball fell perfectly for him after a corner, but two Newcastle defenders made desperate blocks from goalbound efforts.
Four minutes of added-on time were signalled and Man United laid siege to the Newcastle goal but, after a number of corners and the excellent Dubravka making a world-class reaction save to deny Michael Carrick from close range, the home side were left to celebrate a potentially-decisive result in their attempts to remain in the top flight.
NEWCASTLE UNITED (4-4-1-1): Dubravka; Yedlin, Lascelles, Lejeune, Dummett; Ritchie, Shelvey, Diame, Kenedy (Atsu 84'); Perez (Hayden 94'), Gayle (Joselu 80')
MANCHESTER UNITED (4-2-3-1): De Gea; Valencia, Smalling, Jones, Young; Matic (McTominay 77'), Pogba (Carrick 66'); Martial, Lingard (Mata 66'), Sanchez; Lukaku