BOSTON (AP) — Framber Valdez lost his perfect game in the fifth inning and then bounced the next pitch off the batter’s leg.

Astros manager Dusty Baker headed for the mound.

“It was surprising more than anything,” Valdez said, noting that a visit from the manager usually means his night is over. “The first thing I did was look back to the bullpen to see if anyone was out there. I saw nobody was there.

“He just came out and told me ... ‘You know what you’re doing out here, so just breathe,’” Valdez said. “He gave me the confidence to get out of the inning.”

And much more than that.

Perfect through four, the Houston left-hander took a two-hit shutout into the seventh and became the first pitcher this postseason to complete eight innings, leading the Astros over Boston 9-1 on Wednesday for a 3-2 lead in the AL Championship Series.

Yordan Alvarez had three hits and three RBIs for Houston, which could clinch a second trip to the World Series in three years with a victory at home on Friday night.

The Red Sox need a win to force a deciding seventh game on Saturday.

“We came back to Boston exactly where we wanted to be: We were 1-1,” Red Sox starter Chris Sale said. “Not in a good spot going back to Houston. There’s no denying that, but this team has won two games in the playoffs back-to-back before, and we think we can do it again.”

One day after the Astros scored seven runs to break a ninth-inning tie, they hung another crooked number on the Fenway Park scoreboard, chasing Sale while scoring five runs in the sixth. Alvarez, who homered in the second and singled in the fourth, had a two-run double to break things open.

That was plenty for Valdez, who extended the staff’s shutout streak to 14 straight innings before Rafael Devers homered with one out in the seventh — one of just three Boston hits.

Valdez departed after retiring the Red Sox in order in the eighth — completing three full turns through the Boston lineup, a dramatic break from the prevailing baseball wisdom.

“It makes me feel great” to show that starters can still have that kind of impact on a game, Baker said.

“Today, it was in the hands of Framber,” he said. “This was in this hands of Framber, and, really, in the hands of Alvarez.”

In all, Valdez gave up one run on three hits, one walk and a hit batter, striking out five. He was also the first opposing pitcher to last eight innings in a postseason start at Fenway since Cleveland’s Charles Nagy went eight in the 1998 Division Series.

Ryne Stanek pitched a perfect ninth while the rest of Houston’s relievers rested. Astros starters had not lasted three innings all series, pitching to a 18.90 ERA in the first four games and giving up 10 homers — including a record three grand slams.

Valdez was not much better, allowing two earned runs in 2 2/3 innings in Game 1.

“I didn’t get frustrated at all. I wasn’t down on myself,” Valdez said. “I just worked the entire time and I had my mindset set that I was just going to come out and have a way better outing. And that’s what I was able to do tonight.”

Valdez retired the first 12 batters on Wednesday — eight on grounders, four on strikeouts. Devers singled to lead off the fifth, then Valdez bounced the next pitch off J.D. Martinez’s leg. The Astros escaped when Hunter Renfroe grounded into a double play and Alex Verdugo bounced out to first.

“Everybody knew he had a no-hitter, and then they get a hit, and then he hits the batter,” Baker said. “That’s the time that you’ve really got to settle him down and just take the air out the ball, because the crowd was about to get into it. And he threw up a double-play pitch and then he went back to dealing again.”

Sale started almost as well, allowing just two hits — both to Alvarez — in his first five innings. But he walked Jose Altuve to start the sixth, then Michael Brantley nubbed one toward third. Devers fielded it and made the throw in time but Schwarber dropped it at first; after sliding into second, Altuve popped up and took off for third, which was uncovered.

Brantley moved up to second on a groundout to the pitcher, then Alvarez doubled to left, scoring two to make it 3-0 and chasing Sale. Ryan Brasier struck out Carlos Correa before giving up an RBI double to Yuli Gurriel and a two-run single to Jose Siri that made it 6-0.

Brantley added an RBI single in the seventh, and Gurriel singled in two more in the ninth.

Sale was charged with four runs — two earned — on three hits and two walks, striking out seven in 5 1/3 innings.

“I was good for five, and then I sucked for one,” he said. “I told myself coming into this game I had a job to do; obviously didn’t get it done. But I left (it all) out there on that mound tonight, that’s for damn sure.”

The Red Sox had won seven straight postseason games at home — dating to the 2018 ALCS — before blowing an eighth-inning lead on Tuesday night. They had never lost back-to-back postseason games under manager Alex Cora.

UP NEXT

Nathan Eovaldi, who won Game 2 but came on in relief and lost in Game 4, will start Friday for Boston. Baker said he had not decided on a starter.