Germany are the seventh team through to next month's UEFA European Under-19 Championship in Hungary.

Marcus Sorg's team headed into their final elite round Group 5 encounter against Spain knowing a draw would be enough to qualify. La Rojita, though, had also won both of their first two fixtures and looked on course to get the victory they needed to pip Germany to top spot when Munir El Haddadi put them in front after just six minutes, his third goal in the section. Germany, though, drew level through Davie Selke and then went in front via Julian Brandt before the interval. Felix Lohkemper made it 3-1 in the second half and Spain's misery was compounded by the late dismissal of Ivi.

That completed a perfect mini-tournament record for Germany in Vigo. Though they were frustrated for long periods in their opener against Lithuania, they emerged as 2-0 winners thanks to Fabian Holthaus and Hany Mukhtar. Spain were, ultimately, equally comfortable against Denmark. The Danes had drawn level through Marcus Mathiasen after Sandro Ramírez's 33rd-minute penalty, but Luis de la Fuente's side registered a 3-1 triumph following goals from El Haddadi – who scored twice for FC Barcelona in the UEFA Youth League final – and Unai Lopez.

El Haddadi was also on the mark in Monday's 2-0 defeat of Lithuania, Ramírez with another spot kick in the final minute. Germany were even more emphatic against Denmark, racking up a 4-0 win thanks to two goals from the highly-rated Max Meyer and one apiece for Mukhtar and Marc Stendera. All that meant a point against Spain would have been enough for them to progress on goal difference; as it turned out, they finished in style with Levin Öztunali and Joshua Kimmich controlling the midfield and ensuring Ramírez had little service while keeping Meyer, Mukhtar and Brandt well supplied.

"Its a great feeling to win this tournament," Germany coach Marcus Sorg said. "I think we put on a very good perfomance, showing discipline and organisation to beat Spain. If you watched our games here you would say we deserved to come first, we have played three tough games here in Spain and we won the last one against Spain, it's great.

"This week in Vigo has been very nice but we knew that we had very hard games and in the last few days we had the pressure of the last game. But we are very happy and I'm very proud about all the players because they put on a good performance."

Germany will join hosts Hungary, Ukraine, Bulgaria, Israel, Serbia and Portugal at the final tournament, which run from 19-31 July, with the draw at 12.00CET on 19 June. Russia, Norway, Austria or Romania will take the eighth and last spot when Group 6 concludes on Tuesday.