The Tuscans had already been relegated this afternoon by virtue of 17th-placed Genoa's goalless draw with Inter Milan, but debutant Fabrizio Grillo gave the travelling faithful a boost with his first-half finish.
Napoli secured second place - the club's highest finish since 1990 - thanks to victory at Bologna on Wednesday and with the San Paolo crowd demanding one last push on home turf, Edinson Cavani levelled in the 73rd minute.
A 23rd league win of the campaign was suddenly up for grabs as Siena fell apart in the final stages and Hamsik duly nudged home a winner deep into time added on.
Cavani's quest for a 35th goal of a remarkable season continued and the Uruguayan first bared his teeth with a shot from Omar El Kaddouri's ball across the box.
Gianluca Pegolo parried that time and in the 11th minute he managed to punch Gokhan Inler's piledriver out for a corner.
But after Cavani rattled a post with Siena's defence prone from another corner, the spark went out of Napoli's game.
A series of half chances for Swiss striker Innocent Emeghara helped Siena grow in confidence and, in the 36th minute, they took the lead.
Former CSKA Sofia defender Grillo, a January signing, was the surprise candidate to drive the ball home left-footed at the end of a swift raid forward.
Cavani failed to produce an instant response for Napoli, wasting a splendid cross from Giandomenico Mesto by heading wide, and the hosts were spared when Emeghara clipped just over the crossbar at the end of the subsequent counter-attack.
Then, three minutes before the interval, Pegolo pulled off a stunning save to deny Cavani once again.
Salvador Agra kept Napoli on their toes as play resumed by surging into the area on a mission to pick out Emeghara, who came up just short.
The Swiss' follow-up header sailed over the bar but, despite a spell on the backfoot, Napoli were giving precious little space away.
In the 53rd minute Cavani had the ball in the Siena goal but the offside flag denied him an equaliser. He would not wait much longer to score, however, as Napoli drew level 12 minutes from time.
There were groans as El Kaddouri's stinging snapshot clattered the bar but Cavani duly stole in to head home the rebound.
After seeing their own destiny taken out of their hands earlier in the day, Siena would perhaps have been content to settle for a point for their spirited performance.
But it was not to be as Hamsik denied the Tuscans any reason to be cheerful three minutes into stoppage time by steering the ball home with his outstretched left boot.