Hamsik's pass released Vladimir Weiss to score in the 32nd minute at the Stade Pierre Mauroy and the Napoli star doubled the lead in style right on the stroke of half-time.
Russia pushed in the second half but were left with too much to do, even if Denis Glushakov got one back in the 80th minute to set up a grandstand finale.
The result allowed Jan Kozak's team to bounce back from the 2-1 defeat to Wales with which they started their Euro 2016 campaign and put pressure on their Group B rivals before England take on the Welsh in Lens on Thursday.
The build-up to this match in far northern France had been overshadowed by hooliganism fears with Russia having been told they would be thrown out of the competition if there was any repeat of the crowd trouble at the end of their draw with England in Marseille.
More From This Section
However, there was a much calmer atmosphere inside the stands, while the match was played with the stadium roof closed.
After a slow start Russia grew into the game and their powerful centre-forward Artem Dzyuba, of Zenit St Petersburg, nearly caught out Slovakian 'keeper Matus Kovacik with a header after good play down the right by Igor Smolnikov.
Dzyuba then displayed his strength to set up Fedor Smolov for a low shot that fizzed inches wide of the left post as the half-hour approached, but soon after that Slovakia were in front.
Leonid Slutsky's side were stunned but there was worse to come for them, and better from Hamsik, as the interval approached.
The Russian defence was still organising itself when Weiss played a corner short to Hamsik. Oleg Shatov came across in an attempt to block Hamsik but the 28-year-old turned back onto his right foot and curled a tremendous effort in off the far post.
Slutsky changed his two central midfielders at half-time, replacing Roman Neustaedter and Aleksandr Golovin with Glushakov and Pavel Mamaev.
It was Glushakov of Spartak Moscow who reduced the arrears in the 80th minute, heading home after Shatov had played a one-two with Roman Shirokov and crossed from the left byline. But Slovakia held on.