Palmeiras struck five minutes in through Raphael Veiga but ex-Inter Milan forward Gabriel Barbosa equalised in the second half for 2019 winners Flamengo.
On-loan Manchester United midfielder Andreas Pereira committed a horrible mistake in the 95th minute to allow Deyverson to run through and earn Palmeiras the biggest club title in South American football for the second year in a row, and third time overall.
"Our team was very good and very focused today. We literally left our lives on the field. We had to play like this, it was a Libertadores final," said Palmeiras captain Gustavo Gomez.
Only the fifth final to contain two teams from the same country in the tournament's 61-year history, it was the first ever Libertadores showpiece to feature the winners of the previous two editions.
Sao Paulo-based Palmeiras, who beat Santos to lift the 2020 trophy in January, took the lead at the Estadio Centenario when Veiga rifled in a cutback from Mayke after a superb pass out of defence by Gomez.
Barbosa, the competition's leading scorer with 10 goals coming into the final, headed wide before Uruguay international Giorgian De Arrascaeta forced a sharp save from Palmeiras goalkeeper Weverton.
Diego Alves kept Flamengo in the game with a flying stop to tip over from Rony early in the second half, with former Chelsea and Arsenal defender David Luiz denied by another good save from Weverton.
Flamengo forward Bruno Henrique headed narrowly wide at a corner, but the Rio de Janeiro club drew level as Barbosa -- nicknamed "Gabigol" -- beat Weverton at his near post on 72 minutes.
Two late goals from Barbosa won Flamengo the 2019 final against River Plate of Argentina, and they missed a golden chance to snatch victory when Michael drilled wide with just Weverton to beat.
It proved costly when Deyverson, brought on at the start of extra time, caught Pereira in possession and burst free to slot home the winner as Palmeiras became the first club to win back-to-back titles since Boca Juniors in 2000-01.
Deyverson had played sparingly in the previous two rounds but emerged as the unlikely hero, 10 months after Breno Lopes popped up with a 99th-minute goal against Santos with virtually the final touch.
Palmeiras, also Libertadores winners in 1999, will return to the FIFA Club World Cup next year in the United Arab Emirates, joining European champions Chelsea and African giants Al Ahly in the competition.