TUCSON, Ariz. -- Connor Halliday threw 25 yards to Isiah Myers for the tie-breaking touchdown with 2:15 to play to give Washington State a 24-17 upset over Arizona on Saturday.

Halliday completed 39 of 53 passes for 319 yards and two scores, the junior's seventh 300-yard passing of the season.

Ka'Deem Carey scored both touchdowns for Arizona (6-4, 3-4 Pac-12) on a 30-yard run and a 7-yard reception from B.J. Denker. Carey gained 132 yards on 26 carries, his 13th consecutive 100-yard game.

On the final play of the game, from the Washington State 13, Denker's pass to Samajie Grant in the end zone was caught well out of bounds.

The Cougars (5-5, 3-4) had lost their previous three games by a combined score of 162-83.

Halliday's first touchdown pass, 23 yards to River Cracraft, came after Arizona's botched punt attempt at the start of the second half.

Jake Smith missed field goals of 40 and 34 yards for Arizona. Washington State's Andrew Furney had a 46-yard attempt bounce off the left upright.

The Cougars' winning 80-yard drive came after Smith missed the 34-yarder with seven minutes to go.

On third and nine from the Washington State 38, Halliday threw 10 yards to Dom Williams. Halliday hit Teondray Caldwell for 19 yards to the Arizona 31. Then on third-and-four at the 25, Halliday threw to the wide open Myers, who dodged a tackler and ran a few steps to the end zone.

The Wildcats moved downfield and, on fourth and seven from the 28, Denker scrambled nine yards to the 19 for the first down. But Denker was caught at the 13 on third and six and Arizona, without any timeouts left, rushed to the line to get off a final play. Denker lofted it to the end zone and Grant hauled it in, but was a step out of bounds and the Cougars rushed the field in celebration.

The Wildcats spotted the Cougars a 10-0 lead, then got a pair of touchdowns from Carey -- one rushing, one receiving -- to lead 14-10 at the half.

Marcus Mason's 15-yard touchdown run put Washington State up 7-0, then Furney's 24-yard field goal made it 10-0 with 2:05 left in the first quarter.

Arizona struck quickly after the subsequent kickoff, Carey -- in his 13th consecutive 100-yard rushing game -- breaking a series of arm tackles on a 30-yard touchdown run to cut it to 10-7 with 47 seconds still left in the opening quarter.

The Wildcats took the lead with a 15-play, 90-yard touchdown drive. Denker threw wide to Carey, who broke two tackles on a 7-yard scoring play to put the Wildcats ahead 14-10 with 7:37 left in the half.

It was Carey's first touchdown catch of the season.

Arizona threatened again late in the half, but Smith's 40-yard field goal try was wide left as the second quarter ended.

The Wildcats took the second-half kickoff and went three-and-out, then Drew Riggleman dropped the ball trying to punt and Washington State recovered at the Arizona 31. On second-and-18, Halliday threw over the middle to Cracraft for a 23-yard touchdown and the Cougars were back on top 17-14.

The Wildcats moved down the field on their next possession, but their drive stalled at the WSU 8 and Smith's 25-yard field goal tied it at 17 with 6:36 left in the third quarter.

The Cougars, in their first game in 16 days, had a chance to take the lead with 10:24 left in the third quarter but Furney's 46-yard field goal attempt bounced off the left upright.

Arizona took over and moved it downfield but Smith's 34-yard field goal try was wide left.

The teams hadn't met since 2010 and Washington State hadn't played in Tucson since 2009.