Baltimore tied the score 3-3 with a two-run sixth, and Valbuena homered for the second straight day with an opposite-field drive, two-out to left-center field off Tyler Wilson (2-3).
Gattis has four homers and six RBI in eight games since his return from Double-A Corpus Christi, where he went to prepare to play catcher in Houston after not working behind the plate since 2014.
Houston starter Collin McHugh yielded three runs and eight hits while fanning a season-high 10 in 5 1/3 innings. Pat Neshek (2-0) got the last two outs of the sixth, and Luke Gregerson allowed one hit in a scoreless ninth for his 10th save in 13 chances.
Wilson allowed four runs -- three earned -- and six hits in six innings, losing his second straight decision.
Baltimore struck out 18 times on Wednesday after whiffing a season-high 19 times in a 3-2, 13-inning loss Tuesday. The 37 strikeouts for Houston pitchers tied the two-game franchise record, set against the Chicago Cubs on May 30-31, 2003
Colby Rasmus reached on Wilson's error in the fourth, and Gattis homered into the left-field seats for a 3-1 lead.
Chris Davis and Mark Trumbo hit consecutive singles starting the sixth, and left fielder Tony Kemp allowed the ball to glance off his glove for an error that advanced the runners. Davis scored on a wild pitch and Pedro Alvarez hit a chopper for a tying single that chased McHugh.
Neshek allowed a two-out double by Hyun Soo Kim and intentionally walked Machado before retiring Schoop.
Orioles: SS J.J. Hardy, who has been on the disabled list since May 2 with a fractured left foot, started doing some workouts this week, but isn't yet ready for full weight-bearing activities. But he should progress to that soon. "Structurally he's fine," manager Buck Showalter said. "That thing's just about healed. So I think that should happen shortly."
Astros: OF Carlos Gomez, who is on the disabled list with a bruised left ribcage, went 1 for 4 with a solo home run in his second rehabilitation start for Double-A Corpus Christi on Wednesday night. He'll likely make several more starts there before returning to Houston.
Orioles: Kevin Gausman (0-1, 2.70) is scheduled to make his seventh start on Thursday. Gausman lost his first game, but hasn't factored in the decision in any of his five starts since then. He yielded eight hits and one run in 6 2/3 innings of a 3-1 win over the Angels in his last outing.
Astros: Lance McCullers (0-1, 5.91) will make his third start on Thursday. McCullers, who spent the early part of the season on the disabled list with soreness in his right shoulder, allowed five hits and two runs while striking out seven in six innings in his last start, but took the loss in a 2-1 win by the Rangers.