The Dodgers sent Juan Nicasio (0-1) to the mound in the 10th. Angel Pagan singled and stole second before Brandon Belt was intentionally walked. Maxwell, who was robbed of a hit by Howie Kendrick in the eighth, hit a line drive down the left-field line to plate the winning run.
Brandon Crawford tied the game in the ninth with an RBI triple. Belt also knocked in a run for the Giants, who recorded their first sweep of the season and their first sweep over the Dodgers since May 3-5, 2013.
San Francisco starter Ryan Vogelsong gave up two runs on three hits while striking out five over six innings. Santiago Casilla (2-0) got the win after stranding the bases loaded in the top of the 10th.
Alex Guerrero and Adrian Gonzalez hit solo homers for the Dodgers, who have lost three in a row since a seven-game winning streak. Mike Bolsinger made his Los Angeles debut and allowed one run on five hits while striking out five and walking two over 5 2/3 innings.
The Giants scored one run off Pedro Baez in the ninth to make it a 2-2 game. Casey McGehee led off with a single and was replaced on the basepaths by Matt Duffy, who raced home on Crawford's triple to right-center field. Crawford was stranded, however, when pinch-hitter Gregor Blanco struck out swinging, Norichika Aoki popped out and Joe Panik flied out.
Los Angeles loaded the bases with two outs in the 10th, but Gonzalez struck out swinging.
Guerrero and Gonzalez homered in the second and third, respectively, to make it 2-0 Los Angeles.
The Giants didn't advance a runner past first until the sixth. Panik walked and Pagan singled to put men on first and second with one out. After Buster Posey struck out looking, Belt hit an RBI single to center. Chris Hatcher took over for Bolsinger and got Maxwell to go down swinging.
San Francisco failed to score after loading the bases in the eighth. J.P. Howell put a runner on first with two outs before handing the ball over to Joel Peralta. Posey and Belt worked consecutive walks to fill the bags for Maxwell, who was robbed of a hit by Kendrick. The second baseman made a great diving catch on a line drive up the middle to keep Los Angeles ahead.