Milan had been looking for their first win in four games and travelled to Genoa expecting a tough encounter against a Sampdoria side who conceded their first defeat of the season, away to Inter, only two weeks ago.
El Shaarawy had missed most of last season due to injury problems and falling down the club's pecking order following the signings of Mario Balotelli and Japan forward Keisuke Honda.
But under the watchful eye of Italy coach Antonio Conte, the 22-year-old gave the visitors an early lead with a fine strike from the edge of the area.
Stefano Okaka hit a leveller on the stroke of half-time and after Eder gave Sinisa Mihajlovic's side a 51st minute lead Menez beat Sergio Romero from the spot after a Djamel Mesbah handball.
Sampdoria's fifth draw allowed them to replace Lazio in third to sit five points adrift of leaders Juventus ahead of the champions' home game against Parma on Sunday.
Roma, who host Torino, are second, three points off the pace while Milan remain in seventh spot, eight points behind Juve but only two ahead of city rivals Inter, who host Verona on Sunday.
Mihajlovic had no complaints, telling Sky Sport: "It was a great game, both sides played well and both had a lot of chances. I know my lads gave everything they had, that's all I ask.
"We were up against a well organised side, which just goes to underline how far we've come. It finished a draw, so it was a fair result."
Milan coach Filippo Inzaghi, however, felt his side were good enough for the win.
"We played good football tonight, but we deserved to win," said the former Rossoneri striker, who gave special praise to versatile midfielder Giacomo Bonaventura.
"He can play anywhere, on the wing, in the middle and as a playmaker and for a coach that's a bonus. Thankfully he's at Milan."
The prospect of dropping further down the table likely spurred the Rossoneri at what was a difficult venue to pick up points but El Shaarawy allayed fears with a fine strike in the ninth minute.
The Sampdoria defence backed off as the winger ran down the left flank and when he cut in he unleashed a drive which curled past Romero and inside the 'keeper's far post.
El Shaarawy dropped to his knees in a mixture of relief and disbelief, having last hit the net for Milan when he scored against Inter in February 2013.
Milan looked to have done enough for a half-time lead but were stunned when Okaka powered into the box to beat defender Daniele Bonera to Gabbiadini's cross to bundle past Lopez.
Okaka had a hand in Samp's second goal six minutes after the restart when he rose to meet a corner from the right. The ball came back off the post and Eder was quickest to the rebound as Milan vainly protested offside.
Honda paid for a mediocre display by being replaced with Fernando Torres just before the hour to partner Menez up front as Milan resorted to a 4-4-2.
The visitors began pressing for the leveller and were handed a lifeline minutes later when Mesbah handled Menez's pass across the face of goal as he slid in to block in front of a hovering Bonaventura.
French international Menez stepped up to roll the ball past Romero for his first goal since hitting two in a 5-4 win away to Parma nearly two months ago.
Milan saw Bonera sent off for a second bookable offence five minutes from the whistle when he blocked Okaka's run as the Italian powered towards the area.
Samp came agonisingly close to snatching a winner but Lopez pulled off a great two-handed save to stop Roberto Soriano in the final minute of regulation time when the midfielder unleashed a drive from the edge of the area.