DETROIT -- Nick Castellanos blasted a go-ahead home run and an RBI triple, and Victor Martinez drove in three runs as the Detroit Tigers snapped a four-game losing streak with an 8-4 victory over the Pittsburgh Pirates on Wednesday night at Comerica Park.

Martinez, the designated hitter, had three hits, and catcher Alex Avila added a solo home run for Detroit (64-54). Blaine Hardy (2-1) pitched two innings of scoreless relief for the victory.

Buck Farmer, a fifth-round selection in the June 2013 draft, made his major-league debut as Detroit's starter. Farmer, who was called up from Double-A Erie earlier in the day, allowed four runs on six hits. He struck out four in five innings while getting a no-decision.

Left fielder Travis Snider hit a two-run home run for Pittsburgh (64-56). Pirates catcher Russell Martin had an RBI double for his 1,000th career hit, which also extended his hitting streak to 11 games. Losing pitcher Vance Worley (5-2) gave up five runs, three earned, on nine hits in 5 1/3 innings.

Castellanos, the third baseman, smashed his ninth homer into the left-centerfield stands with one out in the sixth to give the Tigers a 5-4 lead. Detroit added three more runs in the seventh on Martinez's two-run single and right fielder Torii Hunter's fielder's choice grounder.

Castellanos gave Detroit a 1-0 lead with a run-scoring triple in the second inning. Martin tied it with a two-out double in the third, driving in third baseman Josh Harrison, who also doubled.

Snider's third homer of the series highlighted Pittsburgh's three-run fourth inning. Designated hitter Pedro Alvarez singled and scored on shortstop Jordy Mercer's triple before Snider ripped the next pitch into the right-field stands.

Detroit scored three runs in the fifth inning to tie it at 4. Avila led off with his 10th home run of the season. First baseman Miguel Cabrera's deep sacrifice fly and Martinez's single brought in the other runs.

NOTES: Tigers RHP Justin Verlander expressed relief Wednesday after an MRI on Tuesday showed no structural damage to his pitching shoulder. Verlander exited his start Monday against the Pirates with shoulder soreness after he allowed five runs in the first inning. "Obviously, you're kind of thinking the worst and hoping for the best," he said. "It seemed like I got the best news possible." ... Detroit optioned RHP Kevin Whelan to Triple-A Toledo to make room for Wednesday's starter, Buck Farmer. ... Pirates 3B/OF Josh Harrison led the majors with a .337 average as a leadoff hitter. "He's sparked us in a number of different ways," Pittsburgh manager Clint Hurdle said. ... Pittsburgh's 23-12 interleague record since last season is second in the majors behind Oakland's 23-9 mark. ... Tigers 1B Miguel Cabrera led the American League with 36 doubles despite not hitting one since July 19.