It was the seventh win in eight games for the Red Sox, and completed a 6-1 homestand in which they score 73 runs.
Boston's Jackie Bradley Jr. had a single to extend his majors' longest hitting streak this season to 21 games.
Heath Hembree (2-0) pitched two innings of relief for the win. Craig Kimbrel got the final three outs for his 10th save.
Boston DH David Ortiz had the day off to rest his legs after getting a double, triple and homer in a game for the first time in his career on Saturday.
Red Sox left fielder Brock Holts was ejected by home plate umpire Joe West after getting called out on strikes.
In a game that had four lead changes, the Red Sox regained the edge 9-8 in the seventh against Scott Feldman (2-3). Hanigan's routine fly ball fell between center fielder Carlos Gomez and right fielder George Springer, allowing Josh Rutledge to score from first. Mookie Betts followed with a triple to the right-center gap.
Trailing 8-6 in the sixth, the Astros scored three times. Third baseman Rutledge's two-out throwing error allowed a run before Colby Rasmus' RBI double tied it. Tyler White followed with a run-scoring single.
The Red Sox had pushed ahead with four in the second against rookie Chris Devenski. Hanigan had an RBI single before Bogaerts homered over the Green Monster, making it 6-3.
An inning later, Hanigan's two-out, two-run single made it 8-4.
Boston starter Sean O'Sullivan was charged with six runs in 4 1/3 innings.
Devenski lasted just two innings in his fourth major-league start, getting tagged for six runs.
Valbuena homered into the bleachers over the Astros' bullpen.