Given the problems Stanford had running the ball against San Diego State and the consequential success K.J. Costello had throwing to JJ Arcega-Whiteside, it was easy to overlook a fine game by the Cardinal defense.

It was gashed by tailback Juwan Washington during a touchdown drive in the second quarter, and the Aztecs moved the ball on a field-goal drive in the third. But aside from those two series and a 39-yard run by Washington late in the third quarter, Stanford’s defense gave up just 70 yards in Friday night’s season opener.

The Cardinal finished with five sacks and seven tackles for loss, limiting the Aztecs to 263 yards of total offense in the 31-10 victory.

The defense even recorded a safety when linebacker Bobby Okereke forced quarterback Christian Chapman into an intentional-grounding penalty from his end zone.

Head coach David Shaw said Tuesday that it wasn’t easy to get a grip on what the Aztecs were doing offensively.

“They do a really good job of keeping you off balance with formations, with motions, with plays that start off looking the same but that end up being a little different,” he said.

He blamed missed tackles for some of the Aztecs’ big plays, but he said, “We still had guys in position.”

The defense’s task will be much greater when the No. 10 Cardinal host No. 17 USC at 5:30 p.m Saturday. The Trojans lost 4,000-yard passer Sam Darnold, 1,500-yard rusher Ronald Jones and 1,000-yard receiver Deontay Burnett from last year’s team, but they still have plenty of weapons.

In USC’s opening 43-21 win over UNLV, the freshman pass combination of JT Daniels and Amon-Ra St. Brown was impressive. The Trojans beat Stanford twice last year, including a 31-28 verdict in the Pac-12 title game.

Statistically, the oddity of the San Diego State game was that Okereke — named the team’s defensive player of the game — had just three tackles. In addition to the safety, however, he would have had a quarterback hurry despite being given the high-low treatment by Aztec blockers. They were assessed a 15-yard penalty for the chop block.

San Diego State was assessed 125 yards on 11 penalties, compared with just 20 yards on three penalties for Stanford. The Cardinal typically are among the least penalized teams in the Pac-12.

“It’s a big emphasis for us,” Shaw said. “It’s a field position game. To lose field position because of a penalty makes it difficult to win.”

Considering the stress San Diego State put on stopping the run, he gave the offensive line a B — “a B-plus at times” — for its performance.

“There were a lot of things we didn’t prepare them for — a lot of movement, a lot of twists and stunts” by the Aztecs’ front seven, Shaw said. On many of the running plays, there were nine defenders near the line when the ball was snapped — “sometimes two guys in a gap.”

As a result, All-America running back Bryce Love had just 29 yards on 18 carries — and Stanford still won by three touchdowns.

Briefly: Wide receiver/return man Connor Wedington will miss the USC game with an undisclosed injury, as will center Jesse Burkett for the second straight week, Shaw said. … Cornerback Alijah Holder, however, will be back after missing the opener. … Drew Dalman again will start at center, and Devery Hamilton, Foster Sarell and Brandon Fanaika probably will all see action at left guard again. … Jake Bailey’s 63-yard punt Friday, which went out of bounds at the 1-yard line, was the second-longest of his career.

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