Spain set up a quarter-final with England in the European Women's Championship after a late victory over Denmark was enough to see them progress from the group stage.
Marta Cardona headed in the 90th-minute winner to confirm Spain's last-eight spot - though they only needed a draw in Brentford.
Jorge Vilda's side, one of the pre-tournament favourites, finish second in Group B with two wins from their opening three games.
They dominated possession against a stubborn Denmark side, who needed victory to go through.
Spain will now face England on Wednesday, 20 July in Brighton for a place in the semi-finals.
Spain created plenty of chances but struggled to break down Denmark, who carried a huge threat on the counter-attack with Chelsea forward Pernille Harder impressive.
It was Harder who created the first big chance of the match, laying it off to team-mate Karen Holmgaard, who wanted an extra touch when a first-time shot was the better option.
Harder then raced onto a through-ball but could not chip it over Spain goalkeeper Sandro Panos, before linking up with Rikke Madsen, only to force a save at the near post from a tight angle.
Spain eventually settled into a rhythm and should have taken the lead through Athenea del Castillo but she could not nod it over the line in a scramble from close range.
Both managers made changes early in the second half as Denmark worked tirelessly to win the ball back and Spain craved the opening they needed to take the lead.
Eventually it came as Cardona rose highest at the back post to head in the late winner and end Denmark's hopes.
It was an unconvincing display from Spain but, after losing Ballon d'Or winner Alexia Putellas on the eve of the tournament, qualifying for the knockout stages will come with a sense of relief.
Spain through but not convincingly
Spain, ranked seventh in the world, were tipped to go far, given a large majority of the squad come from Barcelona who have reached back-to-back Champions League finals.
However, they had to battle to get out of the group stage.
They went behind within a minute of their opening game against Finland before bouncing back to win 4-1 - and were then beaten 2-0 by a Germany side who are threatening to go all the way.
Denmark put up a very good fight and knowing they had to win to leapfrog Spain in the group standings, they held out for as long as possible.
Harder was a constant menace and fired an attempt inches over the crossbar in the second half, before teeing up substitute Nadia Nadim, only for her shot to be tipped over by Panos.
Spain created plenty of chances of their own and will carry an attacking threat against England in the quarter-finals, but they look vulnerable out of possession.
Before the game, Manchester City and Spain midfielder Vicky Losada told BBC TV "we've not seen the Spanish side that we were expecting" and this narrow success did very little to change that view.
Player of the match
CardonaMarta Cardona
Denmark
Squad number10Player nameHarder
Squad number11Player nameVeje
Squad number4Player nameSevecke
Squad number3Player namePedersen
Squad number1Player nameChristensen
Squad number15Player nameMøller Kühl
Squad number19Player nameThomsen
Squad number5Player nameBoye
Squad number6Player nameHolmgaard
Squad number17Player nameMadsen
Squad number13Player nameJunge
Squad number12Player nameLarsen
Squad number8Player nameHolmgaard
Squad number9Player nameNadim
Squad number7Player nameTroelsgaard
Spain
Squad number11Player nameCardona
Squad number17Player nameGarcía
Squad number13Player namePaños
Squad number9Player nameGonzález
Squad number3Player nameAleixandri
Squad number2Player nameBatlle
Squad number8Player nameMariona Caldentey
Squad number16Player nameMapi León
Squad number12Player namePatri Guijarro
Squad number19Player nameCarmona
Squad number4Player nameParedes
Squad number21Player nameGarcía
Squad number6Player nameBonmatí
Squad number15Player nameOuahabi
Squad number10Player namedel Castillo
Line-ups
Denmark
Formation 5-4-1
1Christensen
19Thomsen3Pedersen5Boye4Sevecke11Veje
17Madsen6Holmgaard13Junge15Møller Kühl
10Harder
1Christensen19ThomsenSubstituted forNadimat 73'minutes3Pedersen5Boye4Sevecke11VejeSubstituted forHolmgaardat 80'minutes17MadsenSubstituted forLarsenat 74'minutesBooked at 89mins6Holmgaard13Junge15Møller KühlSubstituted forTroelsgaardat 58'minutes10HarderSubstitutes
2Thrige7Troelsgaard8Holmgaard9Nadim12Larsen14Bredgaard16Svane18Gewitz20Bruun21Gejl Jensen22Worsøe23SvavaSpain
Formation 4-1-4-1
13Paños
2Batlle4Paredes16León Cebrián15Ouahabi
12Guijarro Gutiérrez
21García6Bonmatí8Caldentey Oliver10del Castillo
17García
13Paños2Batlle4Paredes16León Cebrián15OuahabiBooked at 30minsSubstituted forCarmonaat 45'minutes12Guijarro Gutiérrez21GarcíaSubstituted forCardonaat 45'minutes6Bonmatí8Caldentey Oliver10del CastilloSubstituted forAleixandriat 80'minutes17GarcíaSubstituted forGonzálezat 45'minutesSubstitutes
1Gallardo Núñez3Aleixandri5Andrés7Guerrero9González11Cardona14Sarriegi18Abelleira19Carmona20Pereira22Pina23Rodríguez RiveroReferee:Rebecca WelchAttendance:16,041Live Text
Match ends, Denmark Women 0, Spain 1.
Second Half ends, Denmark Women 0, Spain 1.
Offside, Spain. Sandra Paños tries a through ball, but Marta Cardona is caught offside.
Goal! Denmark Women 0, Spain 1. Marta Cardona (Spain) header from the centre of the box to the top left corner. Assisted by Olga Carmona with a cross.
Stine Larsen (Denmark Women) is shown the yellow card.
Attempt missed. Sanne Troelsgaard (Denmark Women) right footed shot from outside the box is too high.
Attempt missed. Marta Cardona (Spain) right footed shot from outside the box is high and wide to the right following a corner.
Attempt blocked. Aitana Bonmatí (Spain) right footed shot from outside the box is blocked.
Corner, Spain. Conceded by Stine Pedersen.
Esther González (Spain) wins a free kick on the right wing.
Foul by Sofie Junge (Denmark Women).
Mapi León (Spain) wins a free kick on the left wing.
Foul by Nadia Nadim (Denmark Women).
Marta Cardona (Spain) wins a free kick on the right wing.
Foul by Sara Holmgaard (Denmark Women).
Substitution, Denmark Women. Sara Holmgaard replaces Katrine Veje.
Substitution, Spain. Laia Aleixandri replaces Athenea del Castillo.
Attempt missed. Karen Holmgaard (Denmark Women) header from the centre of the box misses to the right. Assisted by Sofie Junge with a cross following a corner.
Corner, Denmark Women. Conceded by Sandra Paños.
Attempt saved. Nadia Nadim (Denmark Women) right footed shot from the centre of the box is saved in the top right corner. Assisted by Pernille Harder.