The Italy international decided a tense encounter in the 77th minute, resolving Milan's immediate problems in Serie A, but leaving them still with plenty of margin for improvement.
Genoa lost their second game in a row to fall behind Milan in the table with the managerial switch from Luigi De Canio to Luigi Del Neri having no immediate impact.
In a game played in a ghostly atmosphere with many Milan fans voting with their feet against the club's recent poor form, neither side managed to warm the hearts of the few present inside the San Siro.
The tension was clearly getting to the Rossoneri players while Genoa, playing their first game under new coach Del Neri, lacked the organisation or a gameplan to hurt their hosts.
It was not long before the home fans were expressing their displeasure when the passes failed to find their man.
The only moment of danger in the first half came just before its conclusion when Pato appeared to have his shirt tugged inside the penalty area by Cesare Bovo, but the referee waved away Milan's lengthy appeals for a penalty.
There was not much difference about the second half either with nerves still affecting both teams.
With a goalless draw looking increasingly likely, Ignazio Abate was sent through by Urby Emanuelson just to the right of the penalty area in the 77th minute.
The linesman's flag stayed down and the Milan full-back's low cross was met in front of goal by El Shaarawy, who stroked the ball in from five yards.
The former Genoa striker did not celebrate in front of his former club's fans, but the Milan fans celebrated the man who has now accounted for six of Milan's 10 goals in Serie A this season.
Without the Italy international, Milan's plight would be much worse than it is, but thanks to his goal, Milan managed to move up to ninth in the table, giving them a hint of optimism.