City, though, remain 14 points off division leaders Liverpool with the reigning champions suffering their fourth defeat of what has been an inconsistent 2019-20 campaign to date.
The home side were dominating the ball early on, but United continued to cause all sorts of problems on the break with the pace of James making it difficult for Angelino down the left.
Ederson then had to keep out a low Jesse Lingard effort down the other end as both teams caused problems inside the opening 10 minutes at the Etihad Stadium.
The champions continued to find space in the wide positions and another half-chance arrived in the 13th minute when Bernardo Silva delivered a low cross into Gabriel Jesus, but Victor Lindelof did brilliantly to make the block before the danger was cleared.
Ederson made another smart save in the 16th minute to keep out a rasping strike from Martial after James had again made a clever run before picking out his teammate.
The opening goal was coming, though, and it arrived from the penalty spot in the 23rd minute.
Initially the spot kick had not been given by referee Anthony Taylor, but VAR adjudged that Bernardo Silva had indeed tripped Rashford, who found the bottom corner to send the visitors ahead.
Rashford should have scored a second in the 26th minute after being fed by Fred inside the box, but the England international curled just wide of the far post.
The forward then hit the crossbar with a clever attempt shortly after with the visitors threatening to pull clear of their off-colour opponents, who just could not seem to close the space at the back.
United fully deserved a second, and it came in the 29th minute when Martial worked some space outside the box before combining with James and then squeezing a low shot into the bottom corner of the net.
There were calls for Solskjaer to lose his job as head coach ahead of Wednesday's clash with Tottenham Hotspur, but his team responded against the capital giants and were simply stunning in the first 30 minutes against the reigning Premier League champions.
David de Gea had to keep out a long-range David Silva strike in the 34th minute, though, before Gabriel Jesus headed a brilliant Kevin De Bruyne cross wide of the post with the home side desperate to halve the deficit before the break.
De Bruyne had City's final attempt of the first period as he landed a free kick on the top of the United goal, meaning that the Red Devils entered the half-time break with a 2-0 advantage.
VAR did have a look at a possible penalty for the home side in the closing stages of the first half after a cross from Kyle Walker hit the hand of Fred, but it was adjudged that no offence had taken place.
Angelino fired over the United crossbar in the early stages of the second period with City showing much more intent in the final third, but the score was still 2-0 heading into the final 35 minutes of action.
The home side had a huge chance to score in the 55th minute when De Bruyne broke into the United box, but the Belgium international saw his strike deflected over the crossbar by Lindelof.
Sterling had a half-chance for Guardiola's side after breaking into the United box, but Aaron Wan-Bissaka did really well to make a last-ditch challenge and force a corner.
De Gea had to make a wonderful save to keep out a strike from Rodri 25 minutes from time, before Ederson prevented Lingard from finding the back of the net shortly after down the other end.
Otamendi was next to come close as he headed wide of the post in the 73rd minute, but despite a lot of pressure, United were relatively comfortable heading into the final 10 minutes of action.
That all changed in the 85th minute when Otamendi headed a corner into the back of the net for 2-1, though, and De Gea had to save from Mahrez in the spell that followed as United defended for their lives.
Five additional minutes were signalled at the end of the 90 and the pressure was relentless, but the visitors held on to pick up another huge three points, putting them firmly in the picture for a top-four spot.
City will continue their Premier League campaign away to Arsenal next Sunday, while United are next in domestic action at home to Everton on the same afternoon.
MANCHESTER CITY (4-3-3): Ederson; Walker, Stones (Otamendi 59'), Fernandinho, Angelino; Rodri (Gundogan 86'), D Silva, De Bruyne; Bernardo (Mahrez 64'), Jesus, Sterling
MANCHESTER UNITED (4-2-3-1): De Gea; Wan-Bissaka, Lindelof, Maguire, Shaw (Young 89'); McTominay, Fred; James, Lingard (Tuanzebe 89'), Rashford; Martial (Pereira 74') body check tags ::