Peru missed a second-half penalty in a 1-0 loss to Argentina in Buenos Aires.
The Danes secured their berth with two games to spare as a 53rd-minute goal from Joakim Maehle helped them to an eighth successive qualifying victory.
A second-half double by Timo Werner and one goal each from Kai Havertz and Jamal Musiala secured Germany's fifth win in their fifth game under new coach Hansi Flick.
The results leave Brazil in top spot with 28 points, six ahead of Argentina.
Argentina failed to score for the first time since June, 2019.
Pele had been hospitalised for nearly a month, checking in for routine exams before undergoing a September 4 operation to remove the tumor.
The 80-year-old football great was hospitalised for surgery to remove a tumour.
The 80-year-old three-time World Cup winner said he was feeling better and joked he still had hopes of playing again.
Everton Ribeiro got his second goal in two games to help Brazil on their way to a 2-0 win over Peru in another World Cup qualifier.
Griezmann struck in each half after his partnership with Karim Benzema bore fruit in satisfying fashion to put the world champions on 12 points from six matches at the top of the group.