AUSTIN (KXAN) — Tennessee head coach Rick Barnes was showered with applause and gifts in his return to Austin for the first game against his former team. The Longhorns’ all-time winningest basketball coach is leaving with the gifts, but not a win.

Texas survived a near-massive collapse in the final six minutes to earn a 52-51 win over No. 18 Tennessee Saturday night in front of a sellout crowd. It was Texas’ first home game sellout since 2016. The Longhorns (16-5, 5-3) won their first game of the season over a ranked opponent after turning what looked to be a decisive win into a nailbiter.

Texas looked great building a two-point halftime lead into a comfortable margin during the first 14 minutes of the second half. The Longhorns played great defense, holding Tennessee to three points during the first 10 minutes for a 42-28 lead.

Courtney Ramey’s layup with 5:34 to go seemed to signal the start of the celebration, but Tennessee had other plans while trailing 51-35.

The Vols started making shots in a flurry with 12 points in just over two minutes of game time. Round Rock McNeil product Victor Bailey Jr.’s layup with 1:28 to go tied the game at 51. Chris Beard and the Longhorns were on the brink of their worst loss of the year.

Timmy Allen’s free throw with 6.2 seconds remaining was the only point for the Longhorns in the final five minutes of the game. It was enough for the win despite Josiah-Jordan James’ open look for three as time expired.

While it was a sellout crowd in support of the Longhorns, most were there to pay their respects to Barnes. He won 402 games at Texas over 17 seasons, taking UT to the Final Four in 2003. Before the game, Beard was intentional in making sure Barnes was celebrated properly for his accomplishments at Texas. Beard said he considers Barnes one of his mentors in college coaching.

Texas played a video before tipoff, highlighting Barnes’ run with the Longhorns. T.J. Ford, Barnes’ point guard for the 2003 Final Four team, was also in attendance and spoke to the crowd before the game.

It won’t be a hospitable environment for Texas’ next game. The Longhorns travel to Lubbock to take on No. 13 Texas Tech Tuesday at 8 p.m. Beard will make his first appearance against Tech since leaving the school for UT in April. The Red Raiders faithful have been waiting 10 months for this game.