The Jayhawks led 5-4 with one out in the top of the ninth, but Texas scored six runs to pull out a 10-5 victory.
"It was a game through eight innings," KU coach Bobby Randall said. "Both teams battled hard."
Kansas fought back from a 4-0 deficit through the top of the fifth inning to tie the game in the bottom half.
Kevin Farmer led off the inning with a single, Casey Spanish was hit by a pitch two batters later and John Nelson walked to load the bases. Ryan Klocksien doubled to right-center field to drive in all three Jayhawks, and Kevin Wheeler drove him home to knot the game at 4-4.
The Jayhawks (14-16 overall, 2-11 Big 12 Conference) took the lead in the bottom of the eighth inning off Texas reliever Brantley Jordan.
Brent Del Chiaro walked to start the inning and advanced to second on a failed pickoff attempt. He moved to third on a fielder's choice by Kevin Farmer and scored on an error by Longhorn third baseman Ryan Brooks.
Pete Smart retired Ryan Hubele in the top of the ninth inning but walked Ben King and was then relieved by Doug Lantz.
Lantz walked Brooks to put the tying run in scoring position and Matt Rosenberg followed with a single past first baseman Wheeler to score King and tie the game.
Rosenberg had nearly popped out to left fielder Matt Tribble in foul ground for the second out of the inning on the pitch just prior to his single.
"I was lucky on that," Rosenberg said of the foul popup. "It looked like it took place in slow motion. I was like, 'Oh, God. Drop. Drop.'"
Sam Anderson extended his hitting streak to eight games with an RBI single, and Jeff Ontiveros drove home Rosenberg and Anderson with a single off Lantz. Omar Quintanilla drove home the Longhorns' final two runs with a double to the right field corner.
"Give them credit," Randall said. "Their bats came alive in the ninth and they were able to steal the win."
Smart threw 135 pitches, the most by any Jayhawk this season, in 8 1/3 innings of work, striking out three and walking six.
"This is a tough one to take," Smart said. "I would rank it right up there as one of the most disheartening losses in my Kansas career."
Texas coach Augie Garrido gave Kansas credit for forcing the No. 22 Longhorns to fight back for the victory.
"They played the game hard," Garrido said. "They played with the will to win. I thought they played a great game and I thought they played their butts off."
Lantz dropped to 1-3 with the loss, allowing five runs in 2/3 innings. Jordan (1-0) picked up the victory for the Longhorns (22-12, 10-3).
Kansas will face Texas again today at 2 p.m. at Hoglund Ballpark in game two of a three-game series.