Gonzalez led off the ninth against Kevin Quackenbush with a long double to center field. Matt Kemp struck out, Andre Ethier was walked intentionally and Juan Uribe walked on a 3-2 pitch to load the bases.
Padres manager Bud Black went with a five-man infield, bringing Jake Goebbert to play a left-handed second base, leaving left field completely empty and positioning center fielder Will Venable and right fielder Seth Smith shallow and straight away.
"We were trying to cut off the run," Black said. "We know he [Ellis] is heavy on the right side, so if Quack executes there and we get a ground ball, maybe we can get out of that."
Ellis took a strike, fouled off two fastballs, took a ball, then lined the walk-off out that was caught by a retreating Smith near the right-field corner as Gonzalez tagged to score.
"He did an incredible job, did what you need to do, drove the ball in the air," Gonzalez said of Ellis' at-bat. "Deep enough to give me a chance to score. That's as professional as it gets."
Gonzalez said the win was important because it assured the Dodgers of going into the break in first place, and he mocked those who criticized the Dodgers for their perceived first-half dysfunction, the notion "that we have a really bad chemistry, and we've got a bunch of underachievers, and we don't deserve to be in first place," he said.
Although Maholm came into the game 1-4 with a 5.18 ERA and without a start since May 14, it was his 250th career Major League start, so he wasn't a newbie to the first inning. He has admittedly struggled with his transition to the bullpen, but he knew he signed with a team that already had big money committed to starting pitchers Clayton Kershaw, Zack Greinke, Hyun-Jin Ryu, Dan Haren and Beckett.
"In the back of my head, I still want to start every fifth day," said Maholm. "But our rotation has done really well, there's no complaints that way. But I wanted to prove to myself that I can still do it. The last time I started, I gave up 10 runs [five earned]. I've done this a long time. So I was in my comfort zone. It wasn't something different. I just went back to my normal routine."
Maholm made seven starts early in the season when Beckett, Kershaw and Ryu were injured, then he went into unfamiliar terrain as a long reliever who gets sporadic use. Now he has the longest current scoreless-innings streak of any Dodgers starter. He allowed two hits and struck out four without a walk.
"I had no expectations coming into the game," he said. "I just went hitter to hitter. I wanted to go deep and didn't want to hang the guys out in the bullpen."
Added manager Don Mattingly: "I felt like it was almost like he was on a mission to show us he could start."
Puig -- who ran into a double play that killed a rally in Friday night's loss -- was ejected in the third inning for calling plate umpire David Rackley "stupid" after taking three called strikes from Ian Kennedy.
After the second strike, Puig put his right hand on his hip and stared at the plate. The scene repeated itself after the third strike. Then Puig and Rackley exchanged a few words. First-base coach Davey Lopes tried to intervene, but Puig insulted Rackley and was ejected by the time Lopes arrived at the plate.
It was Puig's second career ejection. He was replaced in the outfield by Carl Crawford. By game's end, Kemp had played in left field, center field and had moved back to left. Ethier had played in center and right. Scott Van Slyke had played in center. That made for three center fielders, two left fielders and two right fielders.
Meanwhile, Kennedy was firing his best start of the year, matching the Dodgers' staff with a three-hit shutout through eight innings.