SOUTH BEND, Ind. — Winning two straight road games against tough competition proved too tall a task for Stanford. On Saturday night, the wheels came off.

The No. 7 Cardinal’s College Football Playoff hopes took a hit when No. 8 Notre Dame carved out a decisive 38-17 win behind quarterback Ian Book and a tough defense.

“He’s a dynamic player,” Stanford linebacker Sean Barton said of Book. “He made some big-time plays, big-time throws. His feet were particularly important in the game, getting out of the pocket, keeping plays alive.”

Book, who replaced Brandon Wimbush as Notre Dame’s starter a week earlier, passed for 278 yards and four touchdowns without an interception. He also scrambled for 47 yards and kept the Cardinal defenders on their heels with his elusiveness.

The Irish (5-0) had a 550-229 advantage in total yardage, and they had four sacks from tackle Jerry Tillery. They figure to be favored in each of their seven remaining games in the regular season after their first home win over a top-10 team in 14 years.

“We’ve got to run the ball better … and we’ve got to be able to stop the run,” Stanford head coach David Shaw said. “They’re pretty straightforward things that we take pride in. We didn’t do that tonight.”

Stanford (4-1) would need a host of things to break right to have a shot at the CFP. In any case, the Cardinal no longer pass the eyeball test to be a true playoff contender.

They rushed for just 55 yards, continuing their season-long struggle in that area. To make matters worse, Bryce Love limped to the locker room in the third quarter. He had 73 yards in 17 carries, including an early 39-yard touchdown run.

Shaw said he had no word yet on Love’s injury. While much of the postgame questioning centered on the continued problems of the offensive line, he said, “I don’t think any of us did a good job in the run or pass game tonight.”

He said, “It’s not just the offensive line. It takes all 11 guys — the quarterback getting into the right play, everybody staying on their blocks, tight ends and running backs reading it right, the wide receivers blocking downfield. It’s a whole group.”

Shaw took the blame for a sequence at the end of the first half when his offense played high tempo, but Notre Dame broke up a 3rd-and-6 pass. That forced a punt that gave the ball back to the Irish with just over two minutes left.

Book quickly guided the Irish to a touchdown that gave them a 21-14 lead.

“That was a 14-point swing,” Stanford quarterback K.J. Costello said.

Book, a native of El Dorado Hills (El Dorado County), completed 24 of 33 passes. He threw touchdown passes of 6 yards to Nic Weishar, 10 to Chase Claypool, 8 to Miles Boykin and 35 to Alize Mack.

“The quarterback’s got a quick release, great feet,” Shaw said. “He’s athletic enough to get himself out of trouble. Quarterbacks like this — if you don’t get them on the ground — will hurt you.”

Costello completed 15 of 27 passes for 174 yards and a touchdown, a 4-yarder to JJ Arcega-Whiteside.

“We were forced off our typical timing on the perimeter,” Costello said. “They were doing a decent job changing up their coverage, changing up their looks, but I think we had a great feel for what they were doing. … At the end of the day, we’ve just got to play better. We had multiple chances to make big plays.”

Irish tailback Dexter Williams, back from a four-game school suspension, rushed 21 times for 161 yards, including a 45-yard touchdown run.

The Irish extended their seven-point halftime lead to 24-14 on Justin Yoon’s 37-yard field goal in the third quarter.

Getting manhandled was “pretty hard to swallow,” Costello said. “As a team we pride ourselves on being physically dominant. Where do we go from here? There’s no magic formula. We’re going to go back to work. I’m excited to get back on the field.”

Book connected with Boykin on an 8-yard scoring play to open a 31-17 lead with 8:16 left. Thanks to an interception by Te’von Coney on Costello’s next pass, the Irish scored two touchdowns in just 14 seconds.

They immediately scored again on Book’s pass to Mack for a 38-17 lead.

Tom FitzGerald is a San Francisco Chronicle staff writer. Email: tfitzgerald@sfchronicle.com Twitter: @tomgfitzgerald