Spain’s eight-year unbeaten run in qualifying matches ended in a stunning 2-1 defeat at Slovakia in qualifying for the European Championship on Thursday.

It was Spain’s first loss in 36 qualifiers for the European Championship and the World Cup dating to 2006, and ended a run of 14 straight away wins.

“This was completely unexpected,” Spain coach Vicente del Bosque. “We didn’t fail, they won this on their own merits. We played with patience but their keeper made some standout saves.”

Spain goalkeeper Iker Casillas did not, however, shine. He let the opener by him in the 17th minute when he failed to punch out Juraj Kucka’s free kick.

Paco Alcacer leveled for Spain in the 82nd, but fellow substitute Miroslav Stoch headed a cross past Casillas in the 87th with Spain caught looking for the winner that instead fell to the hosts in Zilina.

Slovakia took the lead of Group C.

Spain was left level on three points with Macedonia and Ukraine after they both rebounded from losses in their first matches.

Besart Abdurahimi scored in injury time to grab Macedonia a 3-2 win at home over Luxembourg, while Ukraine won 2-0 at Belarus. Defender Aleksandr Martynovich scored an own goal in the 82nd to gift Ukraine the lead before Serhiy Sydorchuk added another goal in stoppage time.

Striker Diego Costa has nine goals in as many games for his Chelsea club, but he again failed to find the net in his sixth appearance for Spain despite generating its best chances.

After exiting the World Cup by losing its first two matches, Spain bounced back with a rejuvenated team to thrash Macedonia 5-1 in its first Euro 2016 qualifier.

But the same problems in Brazil returned at Slovakia: Casillas, once considered among the best in the world, again let a shot that was powerful but stoppable past him. Costa couldn’t mesh with Andres Iniesta and David Silva in the tight spaces Spain’s passing game causes, and its defense proved brittle when faced with counterattacks.

Despite fielding a starting 11 who all played at the World Cup, it fell to Alcacer to score his second goal in as many games to finally break through Slovakia’s defense when he timed his move to stay onside and reach Jordi Alba’s lobbed pass.

Del Bosque sent Alcacer and forward Pedro Rodriguez on in the second half at the cost of pulling defenders Raul Albiol and Juanfran Torres.

“I took off Albiol and Juanfran because Slovakia were not attacking anymore,” Del Bosque said. “With Cazorla, Pedro and Alcacer, we wanted more attacking power.”

The decision led to the equalizer but also left Spain undermanned when Stoch played a one-two with Marek Hamsik before beating Santi Cazorla to head home a cross for the winner that sent the home crowd into raptures.

Casillas was both at his best and his worst early in the match.

He was caught wrong-footed but reacted in time to make a superb one-handed save of Robert Mak’s strike in the 11th.

But moments after Costa headed Cesc Fabregas’ pass by the bottom of the post, Casillas made an error in Slovakia’s opener that was rare to see before his poor displays in Brazil.

Casillas misjudged the free kick Kucka struck hard but right at him, falling to one side and letting the strike glance off his fists and hit his net.

Spain can take solace that the top two from the nine groups qualify automatically for the tournament in France. The best third-placed team also qualifies automatically, and the other eight teams can qualify through a playoff.