BOSTON — The Boston Red Sox once again failed to clinch the AL East title, losing to the Houston Astros 3-2 Friday night as Alex Bregman homered and drove in three runs.

The Red Sox magic number remained at one to close out the New York Yankees, who beat Toronto 4-0. Boston leads the Yankees by two games — both teams have two games left and they’re each assured playoff spots.

If Boston and New York wind up even, they will play a one-game tiebreaker Monday at Yankee Stadium for the division crown, with the loser going to the wild-card game.

Hanley Ramirez doubled with two outs in the Boston ninth. But with the Fenway Park crowd rooting for a rally, Rafael Devers grounded out to end it, with Ken Giles getting his 34th save. The Red Sox dropped their second in a row and fell to 1-4 on their homestand.

The AL West champion Astros won their fifth straight game and posted their 100th victory of the season. They are one game behind AL Central champion Cleveland for the best record in the league and home-field advantage in the AL playoffs.

Charlie Morton (14-7) retired the first 13 Red Sox batters before Mitch Moreland doubled with one out in the fifth inning.

Boston pulled within 3-2 and had the bases loaded in the sixth, but Ramirez grounded out.

Morton allowed four hits in 5 1/3 innings. Four relievers combined to blank Boston on one hit.

A day after the Astros routed Boston 12-2, they took a 1-0 lead in the third on Bregman’s RBI single off Doug Fister (5-9). Bregman, who had three hits, had a two-run homer in the fifth.

ASCENDING ASTROS: Houston has won 13 of 15. The Astros reached 100 wins for the second time in team history, having won 102 in 1998.

TRAINER’S ROOM: Red Sox: INF/OF Eduardo Nunez (knee) took groundballs and ran sprints, but manager John Farrell said he is “still not game ready.”

UP NEXT: Astros: RHP Lance McCullers Jr. (7-3, 4.01 ERA) has battled injuries in the second half, limiting him to just five starts since the break.

Red Sox: LHP Drew Pomeranz (16-6, 3.38) is 3 1/3 innings shy of setting a new career high for innings (170 2/3 in 2016)