David Ortiz lined a three-run double to the left-center gap with one out in the ninth inning Saturday to give the Boston Red Sox a 5-4 victory over the Detroit Tigers on Saturday.

It was the 18th game-ending hit of his career.

Hideki Okajima (4-3) pitched a perfect ninth inning.

Phil Coke (6-2) took the loss after coming in with one on in the ninth. The only batter he retired was Marco Scutaro, who hit a long fly ball that left-fielder Don Kelly jumped to grab in the top of the webbing of his glove.

The Red Sox trailed 2-0 on Miguel Cabrera's 26th homer in the first inning and fell behind 4-0 in the fourth. Ortiz earlier struck out with the bases loaded in the seventh and with runners on second and third in the sixth.

But he got another chance in the ninth when Darnell McDonald beat out an infield single to lead off the inning, and Coke came in to relieve Ryan Perry. Scutaro's drive was more of a warning shot: Pinch-hitter Jed Lowrie doubled to the same part of the field, and then Kevin Youkilis was walked to load the bases.

Ortiz, who was 0 for 8 with three strikeouts against Coke in his career, showed bunt against the shifted defense on the first pitch, then took another pitch for Ball 2. After fouling one off, he lined the next pitch into the left-center gap as the runners raced around the bases.

Youkilis slid across the plate without a throw, while Ortiz celebrated at second base.

His teammates soon joined him there.

Ortiz, McDonald and Billy Hall all had a pair of hits for Boston, and Ryan Kalish also had two hits in his major league debut. The Red Sox, who failed to make a big trade by the 4 p.m. deadline, won for just the 10th time in 24 games since improving to a half-game behind the first-place New York Yankees on July 3.

Max Scherzer took a shutout into the seventh inning, leaving with a 4-0 lead thanks to Cabrera's two-run homer in the first and Ramon Santiago's RBI single in the second and run-scoring double in the fourth. Boston made it 4-2 in the seventh before Perry struck out Ortiz with the bases loaded to end the inning.

NOTES: At the trading deadline, the Red Sox acquired C Jarrod Saltalamacchia from the Texas Rangers for two minor leaguers, a player to be named and cash. They also sent RHP Ramon Ramirez to the San Francisco Giants for pitching prospect Daniel Turpen, designated OF Jeremy Hermida for assignment and selected OF Kalish from Triple-A Pawtucket. LHP Dustin Richardson was also recalled from Pawtucket. ... The Tigers traded OF Wilkin Ramirez to Atlanta for a player to be named or cash. ... Tigers RHP Armando Galarraga says he will make his next start. He left Friday night's game after being hit by a line drive from the bat of Youkilis on his right ankle. ... Two players had their first major league hits in their first at-bats: Detroit's Jeff Frazier and Boston's Kalish. ... Tigers manager Jim Leyland signed a couple of baseballs for a woman in the stands who was hit by an errant throw during batting practice. ... Daisuke Matsuzaka allowed four runs on eight hits and two walks, striking out five in six-plus innings. ... Scherzer had been 0-6 with a 6.60 ERA on the road since winning in Seattle April 18.