Kershaw (14-9) gave up just three hits in bringing the Dodgers' once-promising season to a winning conclusion.
Los Angeles was 17 games above .500 in mid-June, but finished only 10 games over the break-even mark and wound up eight games behind San Francisco in the race for the National League West title.
Los Angeles was clinging to a 2-1 lead heading into the eighth, but Alex Castellanos hit a solo shot in that inning and Juan Rivera had a two-run blast. The homer by Castellanos was his first in the majors.
The loss went to reliever Clay Hensley (4-5), who surrendered the go-ahead run in the sixth inning.
San Francisco, World Series champion two years ago, will face Cincinnati in the best-of-five division playoff round.