The Brewers slipped to the brink of elimination in the playoff race, falling five games behind St. Louis in the battle for the National League's No. 2 wild card berth.
Brett Wallace and Castro hit back-to-back homers in the fifth to give Houston a 5-1 lead. Castro also hit a solo shot in the eighth in helping the Astros fight off a Brewers' comeback bid.
Milwaukee scored twice in the ninth and had the potential tying run on first base when Norichika Aoki grounded into a game-ending double play.
Wilton Lopez picked up his ninth save despite giving up those two late runs. He salvaged the win for Edgar Gonzalez (3-1), who allowed three runs on four hits in 5 2/3 innings.
Yovani Gallardo (16-9) took the loss after being touched for five runs on eight hits in 5 2/3 frames.