Houston Astros' L.J. Hoes, left, beats the ball and Seattle Mariners catcher Humberto Quintero to the plate to score from first base on a Jason Castro double in the fourth inning of a baseball game Thursday, Aug. 29, 2013, in Houston. (AP Photo/Pat Sullivan)— AP

+Read Caption

Houston Astros' L.J. Hoes, left, beats the ball and Seattle Mariners catcher Humberto Quintero to the plate to score from first base on a Jason Castro double in the fourth inning of a baseball game Thursday, Aug. 29, 2013, in Houston. (AP Photo/Pat Sullivan)
/ AP

Seattle Mariners' Franklin Gutierrez (21) is welcomed back to the dugout after hitting a two-run homer against the Houston Astros in the fourth inning of a baseball game Thursday, Aug. 29, 2013, in Houston. (AP Photo/Pat Sullivan)— AP

+Read Caption

Seattle Mariners' Franklin Gutierrez (21) is welcomed back to the dugout after hitting a two-run homer against the Houston Astros in the fourth inning of a baseball game Thursday, Aug. 29, 2013, in Houston. (AP Photo/Pat Sullivan)
/ AP

HOUSTON 
Franklin Gutierrez hit a two-run homer after Nick Franklin gave Seattle an early lead with a solo shot and the Mariners held on for a 3-2 victory over the Houston Astros on Thursday night to end a six-game skid.

Franklin put the Mariners on top with his one-out homer off Jordan Lyles (6-7) in the first inning.

Raul Ibanez singled to start the fourth inning. Franklin Gutierrez's homer to left field with one out pushed Seattle's lead to 3-0. Gutierrez had three of Seattle's six hits to finish a triple shy of the cycle.

Seattle starter Erasmo Ramirez (5-1) allowed five hits and two runs and tied a season high with seven strikeouts in 5 2-3 innings.

Yoervis Medina struck out three in 1 1-3 perfect innings before Danny Farquhar threw a scoreless ninth for his 10th save.

Jason Castro had an RBI double in the fourth and Brett Wallace homered in the fifth to cut the lead to 1. But Houston couldn't string together any hits after en route to its third straight loss.

Lyles allowed four hits and three runs with a pair of walks in six innings.

Ramirez sailed through the first three innings, including striking out the side in the third. L.J. Hoes got Houston's first hit with a single to start the fourth before Castro's one-out double sent him home to make it 3-1.

Wallace opened Houston's fifth with his homer to right-center to cut Seattle's lead to 3-2. Ramirez shaken up a bit with two outs in that inning when he took a comebacker to his foot on a single by Robbie Grossman. He was checked out by trainers and threw a few warmup pitches before remaining in the game to retire Hoes and end the inning.

Jose Altuve doubled with no outs in the sixth inning before Ramirez was chased by a two-out walk of Chris Carter. Charlie Furbush retired Wallace to end the inning and Houston's scoring threat.

Lyles retired eight of the last nine batters he faced after the homer by Gutierrez, with the only baserunner coming when Justin Smoak reached on an error by L.J. Hoes with two outs in the sixth.

Medina threw a perfect eighth inning, including striking out the last two batters in the frame. He ended the inning when he caught Castro looking with an 85 mph curveball for a strike. Castro threw his bat in disgust after the call.

Lyles last started on Friday, but got the last out of Houston's win over the Chicago White Sox on Monday for his first career save.

He was replaced by Kevin Chapman who pitched a 1-2-3 seventh before Brad Miller singled on his first pitch of the eighth inning. He struck out Franklin before Kyle Seager drew a walk. He escaped the jam when Ibanez grounded into a double play.

Chapman struck out three in 2 1-3 scoreless innings. He hasn't allowed an earned run in his first 12 major league appearances, which ties a franchise record.

Grossman robbed Dustin Ackley of a hit with a nifty leaping catch to end the fourth inning. Grossman was running and jumped high in the air to snag the hard hit fly ball.

NOTES: The series continues Friday when Seattle's top prospect, Taijuan Walker, makes his major league debut against Brad Peacock. The 21-year-old Walker went 2-0 with a 0.82 ERA in his last two starts in Triple-A. ... Houston manager Bo Porter said catchers Carlos Corporan and Max Stassi, both on the seven-day concussion list, are making progress. Corporan is ahead of Stassi and believes he could come off the DL next week.