Despite Philipp Ochs' hat-trick, their captain's performance was not able to halt the Portuguese attack.
Alexandre Silva's goal put Portugal 3-2 up after both teams had traded the lead to reach 2-2, with Ankrah and Gonçalo Rodrigues scoring around Ochs' goals.
Buta then made it four and rendered a late Ochs penalty - that sealed his treble - meaningless in terms of the team's tournament; Germany can not make the final four.
Perfect start but pegged back before the break
Any worries of Germany's barren run in front of goal continuing from the Italy game were banished almost immediately, as Ochs opened the scoring with a superb team goal. Benjamin Henrichs was heavily involved, but it was Janni-Luca Serra's stylish touch that set Ochs through to finish with power.
Portugal, undeterred, responded well and saw João Carvalho spurn two great chances to get his side level. Instead, it was Germany that came closer still. A quick counter saw the ball drop kindly for Max Besuschkow, only for his rasping effort to cannon back off the crossbar and away to safety.
Looking in control, a mistake at the back handed Portugal their equaliser. A hashed clearance after a penetrating run gave Ankrah plenty of time on the edge of the box to pick his spot and fire past Dominik Reimann. Nevertheless, it was still a fine finish from the young forward to restore parity.
Portugal take control in the second half to send Germany out
Portugal began the second half and it wasn't long until they took the lead for the first time. Just three minutes after the restart, Gonçalo Rodrigues was afforded far too much time on the edge of the area and crashed a swerving drive past the bamboozled Reimann; the Borussia Dortmund 'keeper had been beaten by two special strikes.
Unlike against the Italians, Germany would find their way back into this game. Diogo Dalot clattered into the back of a charging Cedric Teuchert, and a penalty was awarded. Pedro Silva guessed correctly but Ochs' spot-kick nestled perfectly in the corner and gave the home fans some hope.
That was quashed just two minutes later when Alexandre Silva rounded off a counter-attack. Reimann had made an excellent first save, but the Portuguese attackers were queuing up for the rebound. Then, just three minutes following that goal, Buta calmly tucked home a cross to shock the home crowd. From elation to complete despair.
Ochs was again cool from the spot with the final kick of the game to seal his hat-trick, but the damage had already been done to the German cause. They now face Austria on Sunday in a bid to at least qualify for the World Cup in South Korea, while Italy and Portugal do battle to finish first and fend off the Austrian challenge.