The defending Copa America champions responded to the shock of falling behind to a shock Miguel Camargo after only five minutes with two goals by Vargas before Arsenal star Sanchez grabbed a third in the Group D game.
Sanchez added his second in the 89th minute to complete the scoring.
The Chileans will almost certainly meet Group C winners Mexico in the quarter-finals on Saturday, barring a miraculous result in Tuesday’s other match between Argentina and Bolivia.
Chile meanwhile will advance to the quarter-finals still searching for their best form after twice conceding against modest opponents who were thumped 5-0 by Argentina in their previous outing.
The Chileans were given a scare early on when Camargo gave the Panamanians an early lead. Chile defender Gonzalo Jara was the culprit, giving away possession with a lazy pass out of defense that allowed Panama to pounce.
The ball arrived at Camargo’s feet and the midfielder let fly with a venomous low shot which Barcelona goalkeeper Claudio Bravo failed to grasp to leave Panama 1-0 up.
Chile hit back quickly however, leveling through Vargas, who tapped in from close range after Panama goalkeeper Jaime Penedo could only half block a Sanchez shot.
Gary Medel should have headed Chile into the lead on 38 minutes, stealing in unmarked at the back post but heading over from a Sanchez corner.
Yet two minutes before the break, Chile took the lead, Vargas heading in a cross from the left for 2-1.
Five minutes into the second half, it was 3-1. Vargas picked out Sanchez with a lofted pass from one side of the penalty area to the other and the Arsenal star showed great technique to lash a first-time volley into the roof of the net.
Chile were jolted by a second Panama goal on 75 minutes, when Abdiel Arroyo headed in a free-kick from Ricardo Buitrago to make it 3-2 but finished on top to seal the win when Sanchez added his second.