STANFORD, Calif. (AP) K.J. Costello returned to Stanford's starting lineup and led the Cardinal to a 41-31 victory over visiting Arizona on Saturday.

The senior quarterback threw for 312 yards and three touchdowns after missing three games with a thumb injury. Back-up Davis Mills was unavailable.

''Being able to go out and play today was why I came here,'' Costello said. ''I feel a whole lot different playing than not playing. It's everything.''

The Wildcats (4-4, 2-3 Pac-12) went with two quarterbacks, starting the athletic Kahlil Tate, who passed for 205 yards and a pair of touchdowns and rushed for 103 yards and a touchdown.

Showing no signs of discomfort, Costello rifled passes to 12 different receivers, including a pair of touchdown passes to Simi Fehoko and one to Brycen Tremayne, whose only two career receptions have both gone for touchdowns.

''That's a veteran quarterback,'' Arizona coach Kevin Sumlin said. ''He's been in a lot of games, a lot of different situations. He was probably the best player on the field today.'':

Connor Wedington caught seven passes for 61 yards for Stanford (4-4, 3-3) and Michael Wilson had six for 45 yards.

Cameron Scarlett rushed for 102 yards and scored twice. Freshman Ryan Sanborn added a pair of field goals.

''He brings energy that cannot be matched,'' Scarlett said of Costello. ''Having him back, that shows you how dangerous our offense is and how dangerous he is.''

J.J. Taylor rushed for 107 yards for the Wildcats, surpassing 3,000 for his career.

Jamarye Joiner and Drew Dixon caught TD passes from Tate, who moved into eighth-place on Arizona's all-time passing yards list.

Freshman Grant Gunnell played two consecutive series in the first half, leading the Wildcats on an efficient eight-play, 65-yard scoring drive in which he completed all three passes attempted for 34 yards including an 8-yard scoring toss to Jalen Johnson.

''We need to play a complete game, something we haven't done yet,'' Tate said. ''We have to be better as a whole.''

Tate returned to the lineup after Stanford took a 21-10 lead and needed two plays to go 75 yards. Tate raced 57 yards for the score. He tucked the ball in after faking a pass and ran untouched.

CROSSING THE LINE

Stanford's offensive line has been banged up most the year and this was the second time all season the same players started back-to-back games. ''Drew (Dalman) has been playing good football all year,'' coach David Shaw said. ''He's been our mainstay in there. The young guys, bless them, they just go hard.'' Their play may have fooled Arizona's defense. ''We underestimated their O-line,'' Wildcats' safety Tristan Cooper said. ''They are better on the field than they were on film.''

TAKEAWAYS

Arizona coach Kevin Sumlin doesn't call it a controversy. He's just trying to get the most out of his quarterbacks. It's a nice problem to have. Freshman Grant Gunnell, an accurate passer, entered the game for a series or two in each half, sparking a touchdown drive on his first series. The rest also seemed to ignite Kahlil Tate when he re-entered. Two unique quarterback styles will make it tough on opposing coaches who must prepare for both. ''Everybody knew the plan before the game,'' coach Kevin Sumlin said. ''I thought they both played well. We have to cut down our turnovers and penalties and press forward.''

Nothing like getting your starting signal caller back in the lineup. K.J. Costello gave the Cardinal offense a huge boost. After scoring 16 points in its last game with the No. 3 QB, Stanford scored 31 in the first half against the Wildcats. Costello gives his team a hit of confidence that could lead to another winning season.

UP NEXT

Arizona hosts Oregon State on Saturday.

Stanford has a bye next week and travels to Colorado on November 9.

Copyright 2019 by STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.