Croatia have secured first position in Group D courtesy of a 2-1 win over Spain in Tuesday night's Euro 2016 clash.
Both teams entered the clash in Bordeaux having booked their spot in the round of 16, but Croatia needed to overcome La Roja to secure top spot and in theory, a more favourable draw in the first knockout round.
Alvaro Morata sent Spain ahead in the seventh minute of action, but Croatia levelled late in the first period when Nikola Kalinic's delicate finish found a route past David de Gea. Sergio Ramos had the chance to win it for Spain from the penalty spot 20 minutes from time, only to send his effort straight at Danijel Subasic.
There was to be late drama, however, as Ivan Perisic found a route past De Gea in the 87th minute to condemn Spain to their first European Championship defeat since Euro 2004.
Despite being without key duo Mario Mandzukic and Luka Modric through injury, Croatia showed no signs of nerves in the early moments as they passed the ball impressively in the final third of the field.
Darijo Srna could not resist striking a bouncing ball inside the Spain box as the first attempt arrived in the sixth minute, but the full-back's effort was always finding the stands.
It was Spain that made the breakthrough in the seventh minute, however, as Morata turned home from close range after Cesc Fabregas, who had been found by David Silva, delivered towards the far post.
Fabregas's effort looked to be finding the back of the net, but Morata took no chances as the striker grabbed his third goal of the competition and moved level with Real Madrid teammate Gareth Bale in the scoring stakes.
Croatia were a threat though and had a chance of their own in the 12th minute when a mistake from Ramos freed Kalinic, but La Roja stopper De Gea was on hand to make a smart save.
Moments later, De Gea presented Ivan Rakitic with the ball and indeed an open goal after taking too long to clear a back-pass, but the midfielder's effort hit the crossbar before Gerard Pique cleared on his own goal-line.
Silva was next to come close for Spain after releasing a strike from the edge of the Croatian box, but Subasic got down low to make the save as it remained 1-0 with 23 minutes on the clock in Bordeaux.
Vicente del Bosque's side continued to find gaps in the final third as play developed and Silva poked the ball in to Nolito, who fired towards goal, but the attacker's effort was deflected just wide of the post.
Croatia continued to cause La Roja problems, however, and Milan Badelj should have done better just outside the Spain box after meeting a bouncing ball following a half-cleared free kick.
Perisic was next to have a half-chance for Croatia after Srna delivered a cross from the right, but the midfielder, having risen above Juanfran, headed wide of the target.
Spain had two more chances of their own in the final moments of the first half, but Ramos headed wide from a Nolito corner, before Morata took a heavy touch in a dangerous position after another through-pass from Fabregas had split the Croatian defence.
Croatia had their equaliser in the final minute of the first period, however, when Kalinic converted from close range after Perisic had slipped his marker and delivered a cross from the left.
The first half-chance of the second half fell to Juanfran after Silva had poked the ball into the path of the Atletico right-back, but his effort was always moving high and wide of the crossbar.
Morata was next to come close for Spain after Jordi Alba had delivered a low cross from the left, but he just could not find the target under pressure from Tin Jedvaj.
Croatia's first real sight of the Spain goal in the second period arrived in the 58th minute when De Gea palmed the ball into the path of Jedvaj, but the Manchester United stopper was on hand to make a smart save, before Marko Pjaca sent an overhead kick wide of the post.
Del Bosque sat uneasy on the bench as Croatia continued to dominate the ball, and Villarreal's experienced midfielder Bruno Soriano was sent on just before the hour in a bid to regain some control of the Group D clash.
Ramos had a chance to send Spain ahead in the 68th minute after meeting a Silva corner from the left, but the Real Madrid captain missed the post by a few yards.
Ramos had an even better opportunity three minutes later when the referee surprisingly pointed to the spot after Sime Vrsaljko had caused Silva to fall to the ground inside the Croatian box.
Indeed, it was the skipper that stepped forward to take the penalty, but his effort was straight at Subascic, who was three yards off his line before the centre-back had struck the ball.
It was Croatia that scored the game's all-important third goal though as Perisic collected a pass from Kalinic before finding a route past De Gea, who had been deceived by a slight deflection from Pique.
Croatia will face the third-placed team from either Group B, Group E or Group F on Saturday night in Lens, while Spain will take on the winner of Group E, likely to be Italy, on Monday at the Stade de France.