NEW YORK — Masahiro Tanaka pitched seven innings of three-hit ball, and the Yankees finally solved nemesis Dallas Keuchel, beating the Astros’ ace lefty 5-0 on Wednesday for a 3-2 lead in the AL Championship Series.

Gary Sanchez hit an RBI single off Keuchel and later homered to help the wild-card Yankees win for the third straight day at home and move within one victory of their first trip to the World Series since 2009.

The teams head back to Houston for Game 6 on Friday night, when Justin Verlander and the reeling Astros will try to regain their footing following an off day and force a decisive Game 7. Luis Severino is scheduled to start for the Yankees.

Just days ago, the Astros were up two games to none and appeared to be closing in on their second World Series appearance. But, like the defending AL champion Indians before them, the Astros have been unable to put away these poised Yankees, who improved to 6-0 at home this postseason in front of their cheering, chanting fans.

“It’s been unbelievable. I haven’t seen anything like it in Major League Baseball,” Yankees veteran Chase Headley said. “Reminds me of college football games. They’re going crazy the entire game. It’s a huge advantage for us.”

Aaron Judge, Greg Bird and Didi Gregorius also delivered big hits as the Yankees chased Keuchel in the fifth and handed him his first postseason loss. The 2015 AL Cy Young winner had been 6-2 with a 1.09 ERA in eight career starts against the Yankees, including a pair of scoreless outings in playoff wins.

Both of those came at the expense of Tanaka, who lost 3-0 to Keuchel in the 2015 AL wild-card game at Yankee Stadium and 2-1 in Game 1 of this series.

But this night belonged to Tanaka and the Baby Bombers.