The result meant Steve Clarke’s men were guaranteed a top-two finish in Group A with two games to spare.
A Norway victory would have meant Scotland needed a point from their remaining matches, in Georgia and at home to Norway, next month. But a second-half goal from Spain’s Gavi ensured the Scots were mathematically certain to be at next year’s championships in Germany.
It is only the fourth time Scotland have qualified in their history, and the second in a row.
“I would like to congratulate the players for their efforts in qualifying for back-to-back tournaments,” head coach Clarke told the SFA website.
“I’m not sure they will fully realise the significance of their achievement yet but to qualify for successive Euros after more than 20 years is phenomenal and testament to their hard work.”
Spain, who beat Scotland 2-0 in Seville on Thursday to avenge their defeat by the same scoreline at Hampden Park in March, also made sure of their qualification as they moved top of the group on goal difference. They have two matches remaining, against Cyprus and Georgia.
Gavi has the ball in the back of the net, and after a very lengthy VAR review this one counts 🇪🇸
Scotland and Spain are on track to qualify tonight as things stand 🏴#EURO2024 pic.twitter.com/87bHYe5FdB
— Viaplay Sports UK (@ViaplaySportsUK) October 15, 2023
Elsewhere in Sunday’s qualifiers, Georgia's earlier 4-0 win over Cyprus had kept alive their slim hopes of staying in contention in Group A but Spain's result ended that prospect.
Turkey qualified from Group D after a resounding 4-0 win over Latvia, with former Everton striker Cenk Tosun scoring two late goals.
However, Croatia slipped below Wales into third after Mario Pasalic's 75th-minute goal was not enough to spark the comeback needed after Harry Wilson scored either side of half-time.
West Ham midfielder Tomas Soucek's 76th-minute penalty was enough for the Czech Republic to beat the Faroe Islands 1-0 in Group E.
But the group is still in the balance as Poland's 1-1 draw at home to Moldova - Karol Swiderski cancelling out Ion Nicolaescu's opener - kept them in in touch in third and fourth respectively.
Belarus' hopes of finishing in the top two in Group I were ended after Switzerland scored twice in the last two minutes of normal time to snatch a 3-3 draw.
Manchester City defender Manuel Akanji and Burnley's Zeki Amdouni both struck late on for the Swiss, who had taken a 28th-minute lead through Xherdan Shaqiri, to maintain their unbeaten record after Max Ebong, Denis Polyakov and Dmitri Antilevski appeared to have done enough to keep Belarus in the hunt.
Romania went top with a 4-0 victory over Andorra in which Alaves' on-loan Rangers winger Ianis Hagi was on target.