Updated

Tim Stauffer shut down the Dodgers offense while the San Diego Padres hitters broke out of a scoreless funk just in time to avert a three-game sweep and a sixth consecutive loss to a division rival.

Jason Bartlett homered and the San Diego Padres averted a three-game sweep by beating Los Angeles 3-0 Wednesday night.

Bartlett, who had three hits, broke a scoreless tie with a leadoff home run in the sixth against Ted Lilly.

"Just to get a run on the board felt good," Bartlett said. "Our pitchers have been pitching well. We got Stauffer some runs tonight and he pitched well." The Padres stopped their five-game losing streak against the Dodgers.

Stauffer (7-8) gave up six hits, walked one and struck out two.

"I felt good," Stauffer said. "I was able to command really all of my pitches tonight. I got ahead early, and forced them to put the ball in play early and hit some balls hard but hit them at my guys who made some plays when they needed to."

The Dodgers nearly tied it in the seventh. Dioner Navarro led off with a single and Tony Gwynn Jr. reached on a bunt single. First baseman Jesus Guzman fielded Gwynn's drag bunt cleanly, but second baseman Orlando Hudson failed to cover first.

"It was a well-placed bunt and we just weren't able to get him," Stauffer said.

Jamey Carroll advanced both runners with a sacrifice bunt and Stauffer was pulled. Reliever Josh Spence then intentionally walked pinch-hitter Casey Blake — Spence, a 2010 draftee who began the season in Double-A San Antonio, had retired his previous 14 batters.

Spence escaped the bases-loaded jam when he caught a line drive from Dee Gordon and struck out pinch-hitter Aaron Miles on a full count.

"This is a guy who understands how to get people out," Padres manager Bud Black said of Spence. "He knows his game, and that's one of the things that our minor league people told us. He's poised and he's a clear thinker. He keeps the ball out of the middle of the plate, and that's what we've seen so far."

Chad Qualls worked a scoreless eighth before Heath Bell came on in the ninth.

Bell, the subject of trade rumors prior to the July 31 deadline, posted his first save since San Diego opted not to deal the closer, who is in the last year of his contract. The save was Bell's 31st in 33 opportunities.

Stauffer and Lilly (7-11) traded scoreless innings before Bartlett hit a drive that barely cleared the left-field fence. The home run was Bartlett's second of the season and first at Petco Park, and snapped a 16-inning scoreless stretch for the Padres.

Lilly had allowed just three hits prior to Bartlett's homer, and had retired the previous eight batters. He worked six innings, yielding one run on four hits while striking out seven and walking one in his first loss to San Diego in three starts this season.

"That was supposed to be a fastball that was in on his hands," Lilly said, "but it was up and too much out over the plate to which he could get the barrel through it. In those situations, you're in a tight game like that, it's pretty disappointing for me to let a game go like that."

Aaron Cunningham tripled and scored in the seventh. Jesus Guzman singled to score Bartlett for another run in the eighth.

"This was kind of one of our game," Dodgers manager Don Mattingly said. "Last night was one of our games. In these tight games, you have to take advantage of your opportunities."

NOTES: The shutout was San Diego's sixth of the season, while the Dodgers have been held scoreless 11 times. The Dodgers beat the Padres 1-0 the previous night. ... Padres C Nick Hundley began a rehab assignment in San Antonio on Tuesday. Hundley, who had surgery on his right elbow, is expected to return to the Padres during the upcoming 10-game road trip. ... The Dodgers and Padres are off Thursday.