With the score tied 3-3 in the eighth, Pill pounded a pitch from Paco Rodriguez (3-3) down the left field line and into the stands, handing the Giants a late lead. Closer Sergio Romo had to struggle in the ninth to secure the victory.
Los Angeles put Nick Buss at third and Dee Gordon at second with just one out, but Romo struck out Mark Ellis and -- after issuing an intentional walk to Adrian Gonzalez -- induced Yasiel Puig to ground out for his 35th save.
Jean Machi (3-1) was credited with the decision for San Francisco, which took 3-of-4 games from the National League West-leading Dodgers.
Gonzalez drove in three runs for Los Angeles.
2014: The Year in Music [PHOTOS]