World Cup hosts Brazil triumphed 2-1 thanks to Lazaro Vinicius Marques' 93rd-minute winner on Sunday.
Mexico – winners of the showpiece tournament in 2005 and 2011 – looked on track to add a third title to their collection when Bryan Alonso Gonzalez Olivan headed home the opener in the 66th minute.
But Brazil, playing in front of legends Ronaldo and Cafu, rallied courtesy of Kaio Jorge's penalty with six minutes of regulation remaining.
Brazil completed the comeback deep into stoppage time when Lazaro volleyed home the last-gasp winner.
The victory added to Brazil's successes in 1997, 1999 and 2003 as they moved within one of Nigeria's record of five championships.