Ruben Amorim's side were heading for a third consecutive league defeat as they trailed to Josko Gvardiol's header.
But a scrappy derby short of quality had a stunning late twist as a mistake by Matheus Nunes led to a penalty which allowed Fernandes the chance to level from the spot in the 88th minute.
City had hardly got over that shock when seconds later Diallo sent the visiting fans into delirium with a superb finish from the tightest of angles.
City have now won only once in 11 games in all competitions and stay fifth in the table. United moved up to 12th.