Houston has won six of its last seven and handed Seattle its third straight loss.
The Astros pulled ahead in the eighth without an extra-base hit. Kyle Tucker and Yuli Gurriel had back-to-back singles against Rafael Montero (2-1) with one out. An error by first baseman Evan White allowed Tucker to score on a fielder's choice, and Aledmys Diaz singled to score Gurriel.
''We trust each other in the clubhouse,'' Diaz said. ''Nobody tries to be a hero. We just try to hit the strikes and get the walks.''
Will Vest came in and walked Castro, and Jose Altuve followed with a sacrifice fly.
''The bottom of the lineup really picked us up today,'' Astros manager Dusty Baker said. ''Some day, we're going to click on all cylinders, and it's not far off.''
Joe Smith (1-1) struck out one in a scoreless eighth. Ryne Stanek worked the ninth for his first save of the season.
Montero was charged with three hits and four runs, two earned, in 2/3 of an inning.
''That one stings a little bit tonight,'' Mariners manager Scott Servais said. ''I thought we swung the bat a lot better tonight. There were some positives, but unfortunately the eighth inning got away from us. You've got to give some credit to the Astros because they're tough to put away in this ballpark.''
Houston starter Zack Greinke allowed four runs on four hits in four innings, striking out five and walking two.
''I wasn't real sharp,'' Greinke said. ''I didn't feel really locked in and kept missing my pitches by a little bit, over and over again. I tried to make some adjustments and probably got worse from the adjustments I made.''
Seattle catcher Luis Torrens matched a career high with three RBIs, all off Greinke. He entered Wednesday with 14 RBIs in 291 at-bats.
Torrens hit his first home run of the season - the second of his career - an estimated 426 feet on an 87 mph fastball, the first pitch of the third inning. In the fourth, he had a two-run double that gave Seattle a 3-2 lead.
J.P. Crawford also had an RBI double in Seattle's three-run fourth.
Seattle starter Justin Dunn allowed three runs and four hits while striking out two and walking two in 5 2/3 innings.
Kyle Lewis homered in the fifth for Seattle.
Mariners: LHP James Paxton underwent Tommy John surgery last week and will miss the remainder of the season, Servais said. Paxton exited his first start on April 6 with a forearm strain after throwing 24 pitches. ... LHP Nick Margevicius had an MRI that showed inflammation in his left shoulder, and he'll need more tests when the team returns to Seattle.
Astros: DH Yordan Alvarez was placed on the injured list on Wednesday due to health and safety protocols. It's the second time this month that Alvarez was placed on the IL for health and safety reasons. Houston recalled IF Taylor Jones from its alternate training site. Michael Brantley started at DH and went 0 for 5.
PASSING THE BATON
Before Castro's game-deciding walk, Myles Straw drew a free pass to load the bases.
''You hear the crowd, and you want to be the hero, and it's definitely in your head, but at the end of the day, you've just got to breathe and know when to pass the baton to the next guy,'' Straw said. ''We're playing some good baseball right now, and this team expects to win. We're used to that here.''
Baker tied Hall of Famer Casey Stengel for 12th in wins at 1,905. Baker, the only manager in major league history to take five different teams to the postseason, is 98 wins behind Bruce Bochy for 11th.
HE SAID IT
''You've got to bring your A-game and lock it down or a team like that will knock your door down. That's what happened tonight.'' - Servais.
Seattle's Yusei Kikuchi (0-1, 5.70 ERA) opposes Luis Garcia (0-2, 3.00) as the Mariners try to avoid being swept in the four-game series.
More AP MLB: https://apnews.com/hub/mlb and https://twitter.com/AP-Sports
Copyright 2021 STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.