Brazil opened the scoring after just 11 minutes, as West Ham's Lucas Paqueta rose to head home Vinicius Jr's brilliant cross.
However, the South American giants saw their lead swiftly extinguished, with Habib Diallo scoring a superb volley after Joelinton had failed to clear his lines.
Marquinhos then handed Senegal a shock lead, as he inadvertently turned a cross into his own goal, and Sadio Mane added a third with a stunning strike from the corner of the box.
Marquinhos managed to get one in the right net, too, turning home from a corner to make it 3-2, but it wasn't enough. Mane added a fourth from the penalty spot late on after Ederson brought down Nicolas Jackson.
GOAL rates Brazil's players from Estadio Jose Alvalade in Portugal.