SAN FRANCISCO – The Arizona Diamondbacks departed for a nine-game road trip all against the NL West trailing the Giants by four games.
They head home behind by only one to the reigning World Series champions after a winning series at AT&T Park.
Taking two of three in San Francisco this time did plenty for Arizona's confidence that it can contend for a division title after a sweep here back in May featuring three one-run defeats.
"In the grand scheme of things, we got a lot accomplished on the road trip," center fielder Chris Young said. "We played good baseball and got a lot closer in the race. We just need to keep pushing forward from there."
Vogelsong won his career-best sixth straight decision, Orlando Cabrera hit a two-run double and drove in three runs, and the Giants avoided a second straight sweep.
Vogelsong (9-1), the bright spot in a standout rotation this year, helped the Giants snap a five-game losing streak in which they were outscored 31-8, including a 9-0 loss Sunday at Cincinnati, and had their division lead trimmed by four games in as many days.
"I hope we stay in it," D-backs manager Kirk Gibson said. "I know they are the world champions and a very good team. They are very well managed. We got swept the last time we were here."
Carlos Beltran tripled among his three hits, scored twice and drove in a run in his best game since joining the Giants in a trade from the New York Mets last Thursday. San Francisco scored its most runs in a home game so far in 2011.
Beltran and Pablo Sandoval each hit RBI singles in a four-run third against Marquis (8-6), who lost four days after being acquired in a trade with Washington. The Giants scored four more runs in the fifth.
"This game was probably our biggest game to date of the season, with the losing streak. We had to stop the bleeding," Giants manager Bruce Bochy said.
Marquis tossed a five-hit shutout of San Francisco on April 29, but this was Vogelsong's day all the way.
The right-hander allowed one run on five hits, struck out seven and walked three in six innings to lower his NL-best ERA to 2.19. He also owns the lowest home ERA in the majors (1.30).
After Zach Duke's seventh-inning RBI single got Arizona on the board and chased Vogelsong, Guillermo Mota entered and struck out the side in both the seventh and eighth for a career high-tying six Ks.
Aubrey Huff's single in the fifth was the fourth straight hit to start the inning off Marquis, who left after giving up 10 hits and a season-high seven earned runs. Cody Ross had a two-run double moments later to spoil Brad Ziegler's first outing with Arizona since a trade from Oakland on Sunday.
"They have a few new faces but we read the scouting reports," Marquis said. "They were very aggressive. ... I couldn't make the pitches when I needed to."
The Giants were outscored 11-3 in first two games of the series as Arizona moved into a tie for first in the West heading into the finale, but they denied the D-backs the chance to move into sole possession of first place for the first time since a four-day stretch atop the standings that ended June 25.
D-backs slugger Justin Upton struck out three times and had his 14-game hitting streak snapped.
Notes: Marquis' four innings matched his second-shortest outing of the season. ... The Diamondbacks head home for a 10-game stay at Chase Field but get Thursday off before opening a weekend series with the Dodgers. LHP Joe Saunders starts Friday night for his second straight start vs. L.A. after beating the Dodgers on July 31. He will try for his third straight win overall. Saunders has had quality starts in eight of his last nine outings, going 5-2 with a 2.30 ERA.