Portugal beat the Netherlands 2-1 on Sunday to set up a Euro 2012 quarter-final with the Czech Republic and condemn the Dutch to a first group-stage European Championship exit since 1980.
Germany also advanced after defender Lars Bender scored his first international goal to seal their 2-1 win over Denmark which put the Danes out.
Another three points at Arena Lviv confirmed Germany as Group B winners with three victories while Portugal progress as runners-up from the so-called "Group of Death".
The Germans will now play Friday's quarter-final against Group A runners-up Greece in Gdansk, their Euro 2012 base, while Portugal will play the Group A winners the Czech Republic in Warsaw on Thursday.
Needing to win by two clear goals to stand any hope of progressing, Holland took an early lead through Rafael van der Vaart but were undone by goals in each half from man-of-the-match Cristiano Ronaldo.
Runners-up at the World Cup two years ago and top scorers in qualifying, the Netherlands leave Ukraine with their tails between their legs after three consecutive defeats.
Mindful of the pressing need for goals, Holland coach Bert van Marwijk handed starts to both Klaas-Jan Huntelaar and van der Vaart, who replaced captain Mark van Bommel and inherited the captain's armband from him.
Van der Vaart needed less than 11 minutes to vindicate his manager's decision, collecting a pass from Arjen Robben and shaping a delightful 25-yard shot inside the left-hand post to put Holland ahead.
However, if the Dutch thought they were in for a comfortable evening, Portugal quickly had them on their toes with a flurry of chances sparked by Ronaldo drifting inside and brushing the post with a low strike.
Dutch goalkeeper Maarten Stekelenburg was allowed to shine on his 50th appearance, thwarting Helder Postiga following an errant back-pass by Gregory van der Wiel and then showing sharp reflexes to box away a Ronaldo header.
Holland failed to heed the warnings though, and in the 28th minute Ronaldo levelled, powering onto Joao Pereira's incisive, stabbed pass and clipping the ball past Stekelenburg from close range.
Strangely, scoring the opening goal seemed to have inhibited the Dutch, and they were cowed even further by Ronaldo's equaliser.
So often scorned for his international displays, Ronaldo was a man transformed, and after working Stekelenburg with an audacious dipping shot from 35 yards, he crashed a header narrowly wide from a corner.
Van Marwijk gambled in the second half, throwing on winger Ibrahim Afellay for left-back Jetro Willems, but still Portugal came, Nani spurning a good chance by firing at Stekelenburg after Ronaldo had rolled the ball across goal.
The Madrid man was not so forgiving when Nani returned the favour in the 74th minute, checking inside sharply to send van der Wiel sprawling and then calmly beating Stekelenburg at his near post.
Van der Vaart hit the post with a right-foot curler, but it was the only bright moment in what was a desperate second period for the Dutch, who saw Ronaldo wobble an upright in the final minute.
| German defender Lars Bender scored a late goal to secure Germany’s top spot in Group B [GALLO/GETTY]
Lukas Podolski, who was making his 100th appearance for Germany, celebrated his century with the opening goal on 19 minutes which was cancelled out by a Michael Krohn-Dehli just five minutes later before Bender's late winner.
Having made his debut in the 2-2 friendly draw with Poland last September, the 23-year-old Bender was making only his ninth appearance for Germany.
The Germans started at pace and only a superb block by Denmark goalkeeper Stephan Andersen from a Thomas Mueller low drive on six minutes denied the Germans.
Germany got the break through when Mueller fired his pass across the Denmark goal and Gomez let the ball roll for man-of-the-match Podolski to drill his shot home on for his 44th international goal.
The Germans held the lead for five minutes before Bendtner headed back from a corner and Krohn-Dehli, who also scored in the Danes' shock 1-0 win over Holland, got his head to the ball before the German defence.
It was 1-1 at the break, but midfielder Jakub Poulson, in for hamstring injury-victim Rommedahl, clipped the post with his shot on 51 minutes.
The game's tempo dropped noticeably in the second-half with Germany's midfield star Mesut Ozil looking flat as the Danish defenders constantly thwarted the Germans. Podolski was brought off with 25 minutes left as Leverkusen's Andre Schuerrle was given his chance and he soon tested Andersen with a shot.
With ten minutes to go, Germany counter-attacked at pace and Ozil squared for the grateful Bender to score his first international goal and the right-back calmly slotted past Andersen to seal victory.