Kansas State needed a late layup from Barry Brown to hang on, but the Wildcats did just that to knock off Kentucky and secure their spot in the Elite Eight.

No. 9 seed Kansas State downed No. 5 seed Kentucky 61-58 in the Sweet 16 Thursday night, with Xavier Sneed pacing the winning Wildcats with 22 points. Kentucky used 18 points from PJ Washington and another 15 from Sha Gilgeous-Alexander, but the Wildcats missed 14 free throws (12 of them coming from Washington) and Gilgeous-Alexander’s last-second shot to tie the game missed, so John Calipari’s squad will make the trek back to Lexington.

Kansas State looked to be in trouble after Sneed fouled out with just over a minute to go, especially when Kentucky tied things up at 58 on a PJ Washington free throw moments later. Brown’s heroics were actually his third attempt at winning the game for the Wildcats—he had his shot blocked to hell by Washington when he drove to the right side of the lane with 51 seconds remaining, then missed a jumper in the lane five seconds later. It was an offensive board by Cartier Diarra, one in which Diarra dove to the floor and instinctively called timeout with 40 ticks left on the clock, that gave Brown his final attempt, which he finished over the outstretched hands of Washington.

The Wildcats will now face Loyola-Chicago in the Elite Eight on Saturday.