Wales' first major international tournament match in 58 years ended in victory as Hal Robson-Kanu struck late to seal a 2-1 Euro 2016 win against Slovakia.
Gareth Bale stepped up to beat Matus Kozacik with a brilliant whipped free-kick from 30 yards to put his side into an early lead in Bordeaux.
Bale had scored or assisted nine of the 11 Wales goals in qualifying and the Real Madrid forward seemed to have made the difference for his team once more.
But substitute Ondrej Duda had other ideas, shooting low past Danny Ward after superb work by Robert Mak early in the second half.
Another substitute then struck the decisive blow with 10 minutes to go as Robson-Kanu bundled in an untidy finish after Aaron Ramsey created the opening.
Slovakia's unbeaten run ends at eight games as a result of their defeat, with Russia up next for Jan Kozak's side, while Wales will be buoyed ahead of their clash against England in Lens on Thursday.
All the pre-match build-up had focused on Bale against Hamsik, and it was the Slovakia star who was first to threaten with a brilliant solo run inside three minutes.
Hamsik robbed Bale and drove away from three Wales defenders before beating Ward with a low shot, but Davies got back superbly to clear.
That block proved vital as Bale opened the scoring in fine style after just nine minutes.
Bale's first international goal was a free-kick against Slovakia in October 2006 and when Jonny Williams was fouled 30 yards out, the stage was set for a repeat performance.
And the world's most expensive player delivered with a viciously swerving strike that completely deceived a bewildered Kozacik, who took a decisive step the wrong way as Bale hit the ball.
Wales could have had a penalty after 32 minutes when Martin Skrtel barged Jonny Williams over, but even though the incident was right in front of the extra official behind the goal, no foul was given.
After Mak had wasted a 54th minute chance, Bale almost doubled Wales' advantage only for Kozacik to save his powerful header.
Slovakia were back on terms on the hour-mark, though, Mak's driving run into the heart of the Wales half worked an opening for Duda - who had only come on as a substitute 52 seconds earlier - the midfielder finishing well into Ward's bottom-left corner.
Ward, who was thrust into the Wales side at short notice after number one goalkeeper Wayne Hennessey succumbed to a back spasm, then saved from Juraj Kucka as Slovakia pressed.
Ramsey then looped a 72nd minute header over from Robson-Kanu's cross, but he made amends with 10 minutes to play.
His driving run opened a chasm in the Slovakia defence and Robson-Kanu, a free agent after being released by Reading, beat Kozacik with a low finish.
Adam Nemec went close to a late equaliser after getting across Ashley Williams, but his header came back off the post with Ward beaten, leaving Wales to celebrate.
Key Opta Stats:
- Gareth Bale scored with Wales' first ever shot on target at a EURO finals tournament. - Bale is the first British player to score a direct free kick in a EURO finals game. - Ondrej Duda scored after 52 just seconds of coming off the bench, the fastest EURO finals goal by a substitute since Valeron on 12/06/04 v Russia (39 secs). - The goal was only Duda’s second touch of the game after coming off the bench. - Wales have conceded in each of their last five games (including friendlies), their worst run of conceding since March 2013 (11). - Hal Robson Kanu’s goal was his first for Wales since October 2014 (v Cyprus), which was also the last Welsh goal in a competitive game not scored by either Gareth Bale or Aaron Ramsey.