Updated

J.D. Martinez hit his first career grand slam and the Houston Astros avoided a three-game sweep with a 6-3 win over the San Francisco Giants on Thursday.

Matt Downs also homered and Justin Maxwell drove in a run for the Astros, who had dropped 13 of their previous 17 — including a 10-0 loss Tuesday night in which Giants ace Matt Cain tossed a perfect game. Jose Altuve had two hits and walked as the second baseman continues to rank among the major league leaders in average and hits.

Wandy Rodriguez (6-4) went six innings to win his third straight decision, allowing three runs on six hits, and Brett Myers worked the ninth for his 16th save in 17 opportunities.

Brandon Belt hit a two-run homer and Hector Sanchez added a sacrifice fly for the Giants, who are 12-5 over their past 17 games.

Giants starter Barry Zito (5-4) lasted five innings, allowing five runs on five hits. He walked three and struck out three in losing two straight decisions for the first time this season.

After tossing 8 1-3 shutout innings against the Chicago Cubs on June 3, Zito has allowed nine runs on 14 hits over his last 11 innings.

Downs gave the Astros a 1-0 lead with his fourth home run of the season with two outs in the second.

Zito walked Altuve, Brian Bixler and Jed Lowrie in succession to open the third, setting up Martinez's slam that traveled halfway up the left field bleachers. He's allowed four home runs in his past two games after allowing four in his previous eight.

Maxwell's two-out single in the eighth gave the Astros a 6-3 lead.

Belt's third home run in as many days put the Giants on the scoreboard in the fourth. His two-run shot cleared the right field bleachers and landed in McCovey Cove.

Sanchez hit his sacrifice fly in the sixth.

NOTES: Giants 1B Aubrey Huff underwent an MRI to assess damage in his bruised right knee, injured while jumping over the railing following the conclusion of Matt Cain's perfect game Wednesday night. ... Martinez broke a 12-at-bat hitless streak with his slam. He now has 13 RBIs in 10 games against the Giants. ... Astros OF Carlos Lee is slated to start a rehab assignment with Double-A Corpus Christi on Thursday. ... The Astros have signed 26 of their 41 draft picks, including 15 of the first 21. ... Giants IF Joaquin Arias extended his career-best hitting streak to eight games. ... Altuve recorded his 28th multi-hit game.