Caroline Weir’s first-half goal earned Scotland victory over Spain but was not enough to earn a Euro 2017 quarter-final place, as their beaten opponents scraped into the knockout stages.

Anna Signeul, who will now step down as Scotland manager, needed her team to beat Spain by at least two goals and England to defeat Portugal in Tilburg, which they did by a 2-1 scoreline.

The Liverpool midfielder Weir’s goal against the run of play earned victory, despite Spain dominating possession, while the goalkeeper Gemma Fay was lucky to stay on the pitch after appearing to handle the ball outside the area.

Weir pounced after the Spanish goalkeeper, Sandra Panos, miscued her clearance with minutes of the first half remaining, and Nikita Parris’s England goal just after half-time meant Spain were hanging on to second place in Group D by a single goal.

With extra bodies up front, Spain nearly found the equaliser through Maria Paz, who dragged Amanda Sampedro’s assist just wide, before Ifeoma Dieke provided a crucial block to stop the ball falling to any of at least three Spain strikers in the closing moments.

Scotland held on for victory but were unable to create enough chances at the other end and fell agonisingly short of reaching the knockout stages on their tournament debut.

Despite Scotland’s early exit Fay was pleased to prove a point to the team’s critics, insisting the nation “can only get better. We said there was more to come from us, when a lot of people had written us off,” Fay said afterwards.

“There were two people at our press conference yesterday. Nobody gave us a chance. But you should never write off this badge. We could have had more than one tonight and we were inches off that one we needed.

“This team can only get better,” Fay added. “If we do the right things at grassroots level, strive to have that professional set-up, things can be great.”

The Swede Signeul, who departs after 12 years in charge to take charge of Finland, is similarly confident about the prospects of the national team. “It was fantastic how we fought,” she said. “It has been so long that we wanted to get to this tournament that today we had everything to win and nothing to lose.

“I am so proud of them because today we showed what we are about. Now they will qualify for the World Cup. I am sure about that.”