Peru have more than one foot in Copa America quarters after win
Bolivia took the lead from the penalty spot when Marcelo Moreno sent goalkeeper Pedro Gallese the wrong way from 12 yards.
But Guerrero equalized before half-time and Farfan gave Peru a deserved lead before Edison Flores put the seal on Peru's victory in stoppage time at Rio de Janeiro's iconic Maracana stadium. With four points from two games ahead of their final group encounter with hosts Brazil, Peru can rest assured that no team has ever failed to qualify for the knockout rounds with that total since the current 12-team format was adopted in 1993.
Bolivia face a must-win clash with Venezuela in their final game to stand any hope of reaching the quarter-finals. Peru took control of the match early on with pacey right-winger Andy Polo carving out the opening chance, although his left-footed shot was tame and easily saved by Carlos Lampe. Farfan earned a free-kick that he then fired high and wide on 20 minutes and at that time Peru had enjoyed 70 percent possession.
But Bolivia went ahead after Fernando Saucedo's volley cannoned off Carlos Zambrano's arm inside the penalty area, with Colombian referee Wilmar Roldan pointing to the spot after a lengthy delay to consult the video assistant referee. Moreno made no mistake, sending Gallese the wrong way with his stuttering run-up on 28 minutes.
Guerrero equalized just before the break after a mistake by Erwin Saavedra, who was robbed inside the center-circle by Christian Cueva, who sent his captain scampering away with a defence splitting pass. Guerrero rounded the onrushing Lampe and slotted into the empty net.
Polo started the second half as he had the first but this time fired high over the bar. Peru continued to dominate as they had in the first period and deservedly went in front when Farfan soared and hung in the air to head home Guerrero's deflected cross from six yards out.
Saavedra had a golden opportunity midway through the half to make up for his earlier blunder when Gallese could only push out a rasping drive from Raul Castro, but charging in to volley home the rebound he skied it high into the Maracana stands.
Lampe kept Bolivia in the game with a pair of saves from Polo and Renato Tapia. From the resulting corner he dived low to parry a Guerrero header and was on hand to push away a fierce Luis Advincula effort.
As Bolivia pushed up desperately looking for an equalizer, Flores ran onto Farfan's through ball on the break and committed Lampe with a feint before chipping the ball into an unguarded net.