Leon Goretzka scored late to keep Germany in the European Championship after a 2-2 draw against Hungary on Wednesday.

Jamal Musiala made an immediate impact after coming on in the 82nd minute, eluding three defenders to give Timo Werner room to shoot. Werner was blocked but the rebound fell for Goretzka, who shot past goalkeeper Péter Gulácsi in the 84th.

More Images
Germany's Leon Goretzka, left, celebrates with teammates after scoring his side's second goal during the Euro 2020 soccer championship group F match between Germany and Hungary at the Allianz Arena in Munich, Germany,Wednesday, June 23, 2021. (Lukas BarthPool Photo via AP)

Leon Goretzka scored late to keep Germany in the European Championship after a 2-2 draw against Hungary on Wednesday.

Germany's Leon Goretzka scores his side's second goal during the Euro 2020 soccer championship group F match between Germany and Hungary in Munich, Wednesday, June 23, 2021.(Kai PfaffenbachPool via AP)

Germany made the better start but was caught out early yet again in the tournament when Szalai met Roland Sallai’s cross with a flying header on a counterattack in the 11th.

Germany's Leon Goretzka scores his side's second goal during the Euro 2020 soccer championship group F match between Germany and Hungary in Munich, Wednesday, June 23, 2021.(Kai PfaffenbachPool via AP)

But Hungary replied immediately when Szalai played in Schäfer to head the ball past Manuel Neuer.

Germany's goalkeeper Manuel Neuer reacts after the Euro 2020 soccer championship group F match between Germany and Hungary in Munich, Wednesday, June 23, 2021.(Kai PfaffenbachPool via AP)

Portugal drew with France 2-2 in the other group and both progress, while Hungary finished last with two points and has been eliminated.

Germany's Leroy Sane reacts during the Euro 2020 soccer championship group F match between Germany and Hungary at the Allianz Arena in Munich, Germany,Wednesday, June 23, 2021. (Lukas BarthPool Photo via AP)

Germany's Leroy Sane reacts during the Euro 2020 soccer championship group F match between Germany and Hungary at the Allianz Arena in Munich, Germany,Wednesday, June 23, 2021. (Lukas BarthPool Photo via AP)

Germany's Leroy Sane controls the ball during the Euro 2020 soccer championship group F match between Germany and Hungary at the Allianz Arena in Munich, Germany,Wednesday, June 23, 2021. (Lukas BarthPool Photo via AP)

Germany's Leroy Sane controls the ball during the Euro 2020 soccer championship group F match between Germany and Hungary at the Allianz Arena in Munich, Germany,Wednesday, June 23, 2021. (Lukas BarthPool Photo via AP)

Players react after the Euro 2020 soccer championship group F match between Germany and Hungary at the football arena stadium in Munich, Germany, Wednesday, June 23, 2021. The match ended in a 2-2 draw. (Matthias HangstPool Photo via AP)

Players react after the Euro 2020 soccer championship group F match between Germany and Hungary at the football arena stadium in Munich, Germany, Wednesday, June 23, 2021. The match ended in a 2-2 draw. (Matthias HangstPool Photo via AP)

Police officers stand in front of Hungary fans during the Euro 2020 soccer championship group F match between Germany and Hungary at the football arena stadium in Munich, Germany, Wednesday, June 23, 2021. (Matthias HangstPool Photo via AP)

Police officers stand in front of Hungary fans during the Euro 2020 soccer championship group F match between Germany and Hungary at the football arena stadium in Munich, Germany, Wednesday, June 23, 2021. (Matthias HangstPool Photo via AP)

Germany's Joshua Kimmich, left, and Germany's Kevin Volland celebrate after scoring their side's second goal during the Euro 2020 soccer championship group F match between Germany and Hungary at the Allianz Arena in Munich, Germany,Wednesday, June 23, 2021. (Lukas BarthPool Photo via AP)

Germany's Joshua Kimmich, left, and Germany's Kevin Volland celebrate after scoring their side's second goal during the Euro 2020 soccer championship group F match between Germany and Hungary at the Allianz Arena in Munich, Germany,Wednesday, June 23, 2021. (Lukas BarthPool Photo via AP)

It had looked like Ádám Szalai was going to drag his team into the round of 16. The Hungary captain scored one goal early against the run of play and set up András Schäfer to make it 2-1 right after Kai Havertz had equalized for Germany.

Germany's Leon Goretzka, left, celebrates with teammates after scoring his side's second goal during the Euro 2020 soccer championship group F match between Germany and Hungary at the Allianz Arena in Munich, Germany,Wednesday, June 23, 2021. (Lukas BarthPool Photo via AP)

Germany's Leon Goretzka, left, celebrates with teammates after scoring his side's second goal during the Euro 2020 soccer championship group F match between Germany and Hungary at the Allianz Arena in Munich, Germany,Wednesday, June 23, 2021. (Lukas BarthPool Photo via AP)

Germany made the better start but was caught out early yet again in the tournament when Szalai met Roland Sallai’s cross with a flying header on a counterattack in the 11th.

Germany struggled against Hungary’s defensive 5-3-2 formation and was further hampered by heavy rain from a thundershower in the first half.

The home team finally made a breakthrough in the 66th when the normally excellent Gulácsi failed to punch away Toni Koos’ free kick. Mats Hummels headed the ball forward and Havertz made sure from close range.

Germany's Leon Goretzka scores his side's second goal during the Euro 2020 soccer championship group F match between Germany and Hungary in Munich, Wednesday, June 23, 2021.(Kai PfaffenbachPool via AP)

Germany's Leon Goretzka scores his side's second goal during the Euro 2020 soccer championship group F match between Germany and Hungary in Munich, Wednesday, June 23, 2021.(Kai PfaffenbachPool via AP)

But Hungary replied immediately when Szalai played in Schäfer to head the ball past Manuel Neuer.

It would have been enough to send Hungary through to the next round at Germany’s expense, but substitutes rescued the game.

Germany finished second in the group with four points and will next face England at Wembley Stadium on Tuesday.

Germany's Leon Goretzka scores his side's second goal during the Euro 2020 soccer championship group F match between Germany and Hungary in Munich, Wednesday, June 23, 2021.(Kai PfaffenbachPool via AP)

Germany's Leon Goretzka scores his side's second goal during the Euro 2020 soccer championship group F match between Germany and Hungary in Munich, Wednesday, June 23, 2021.(Kai PfaffenbachPool via AP)

Portugal drew with France 2-2 in the other group and both progress, while Hungary finished last with two points and has been eliminated.

More AP soccer: https://apnews.com/hub/soccer and https://twitter.com/AP_Sports

Ciarán Fahey on Twitter: https://twitter.com/cfaheyAP

Germany's goalkeeper Manuel Neuer reacts after the Euro 2020 soccer championship group F match between Germany and Hungary in Munich, Wednesday, June 23, 2021.(Kai PfaffenbachPool via AP)

Germany's goalkeeper Manuel Neuer reacts after the Euro 2020 soccer championship group F match between Germany and Hungary in Munich, Wednesday, June 23, 2021.(Kai PfaffenbachPool via AP)

Germany's Leroy Sane reacts during the Euro 2020 soccer championship group F match between Germany and Hungary at the Allianz Arena in Munich, Germany,Wednesday, June 23, 2021. (Lukas BarthPool Photo via AP)

Germany's Leroy Sane reacts during the Euro 2020 soccer championship group F match between Germany and Hungary at the Allianz Arena in Munich, Germany,Wednesday, June 23, 2021. (Lukas BarthPool Photo via AP)

Germany's Leroy Sane controls the ball during the Euro 2020 soccer championship group F match between Germany and Hungary at the Allianz Arena in Munich, Germany,Wednesday, June 23, 2021. (Lukas BarthPool Photo via AP)

Germany's Leroy Sane controls the ball during the Euro 2020 soccer championship group F match between Germany and Hungary at the Allianz Arena in Munich, Germany,Wednesday, June 23, 2021. (Lukas BarthPool Photo via AP)

Players react after the Euro 2020 soccer championship group F match between Germany and Hungary at the football arena stadium in Munich, Germany, Wednesday, June 23, 2021. The match ended in a 2-2 draw. (Matthias HangstPool Photo via AP)

Players react after the Euro 2020 soccer championship group F match between Germany and Hungary at the football arena stadium in Munich, Germany, Wednesday, June 23, 2021. The match ended in a 2-2 draw. (Matthias HangstPool Photo via AP)

Police officers stand in front of Hungary fans during the Euro 2020 soccer championship group F match between Germany and Hungary at the football arena stadium in Munich, Germany, Wednesday, June 23, 2021. (Matthias HangstPool Photo via AP)

Police officers stand in front of Hungary fans during the Euro 2020 soccer championship group F match between Germany and Hungary at the football arena stadium in Munich, Germany, Wednesday, June 23, 2021. (Matthias HangstPool Photo via AP)

Germany's Joshua Kimmich, left, and Germany's Kevin Volland celebrate after scoring their side's second goal during the Euro 2020 soccer championship group F match between Germany and Hungary at the Allianz Arena in Munich, Germany,Wednesday, June 23, 2021. (Lukas BarthPool Photo via AP)

Germany's Joshua Kimmich, left, and Germany's Kevin Volland celebrate after scoring their side's second goal during the Euro 2020 soccer championship group F match between Germany and Hungary at the Allianz Arena in Munich, Germany,Wednesday, June 23, 2021. (Lukas BarthPool Photo via AP)