Ash led Texas (4-0, 1-0 Big 12) on a 75-yard scoring drive after the Cowboys (2-2, 0-1) took the lead on Quinn Sharp's 24-yard field goal with 2:34 to play.
Ash connected with tight end D.J. Grant for a 29-yard pick up on fourth-and-6 to keep the drive going, and Mike Davis outleaped Justin Gilbert on a 32-yard deep ball to set up Bergeron's winning touchdown.
"He will not be under any more pressure than this, and he couldn't have done this this time last year," said coach Mack Brown, who moved to 7-0 in Stillwater. "He has really grown up. He is the leader of this football team."
J.W. Walsh started in place of injured Oklahoma State quarterback Wes Lunt and threw for 307 yards and two touchdowns.
Joseph Randle added a career-high 199 yards rushing and two touchdowns for the Cowboys, who hung a banner marking last season's Big 12 championship in the east end zone but started their defense of it by coming up short in a wild fourth quarter that featured four lead changes.
The Longhorns had lost at home to OSU each of the past two seasons. Last season, Ash was making his first career start and threw for only 139 yards with two interceptions and no touchdowns in a 38-26 loss.
"That game really haunted me because as a first start, it wasn't the first start that you wanted to have," said Ash, who finished with 304 yards passing and threw his first interception of the season.
"This game kind of means a lot."
D.J. Monroe added a 100-yard kickoff return touchdown as the Longhorns improved to 23-4 in a series in which they have rallied from 28-, 19- and 21-point deficits just since 2004. This was another difficult one for Oklahoma State to take.
Randle lunged in from 2 yards out to put Oklahoma State up 33-28 early in the fourth, only for Texas' potent running game to come alive next. Bergeron also capped that 75-yard drive with a 1-yard touchdown run, as the Longhorns picked up 65 yards on seven carries while moving down the field.
After the ensuing kickoff went out of bounds, Oklahoma State needed just three plays to bolt to the Texas 13. But then that drive stalled, with three straight 2-yard runs -- two by third-stringer Desmond Roland and then one by Randle, who was pulled out for a breather -- and the Cowboys settled for Sharp's field goal.
"Coaches will have second thoughts about plays that were called. ... We have to be able to make those plays and get that stop," Gundy said.
Bergeron's scoring run was reviewed on instant replay after Oklahoma State safety Daytawion Lowe came out of the pile with the ball in the end zone, but officials upheld the call on the field.
"They made a play at the end and they happened to make a play when the clock ran out," Gundy said. "Give them credit."
Settling into his starter's role after splitting time with Case McCoy last season, Ash also threw scoring passes of 44 and 20 yards to Shipley in the first half before the pair hooked up for a 7-yard TD on a fade pass in the third quarter to make it 28-20.
"It's something we haven't been able to do in the last couple years, win a tough game like this on the road," Brown said.
The Longhorns had a losing record in Big 12 play each of the past two seasons after winning the conference championship in 2009.
"The only thing that was important for us tonight was to win," Brown said. "We needed to go on the road, we needed to win against a team that had beaten us twice in a row, we needed to win against a team that had won more games than anybody in the Big 12 the last two years and we needed to win at a place where they hadn't lost for the last two years."
Texas had only 29 yards on its first 22 rushing attempts but gained 106 on its last 20 tries during crunch time. Oklahoma State ran for 275 yards but couldn't punch it in its last time in the red zone.
"It comes down to just your will," said Bergeron, who had 48 yards on 15 carries. "It's not the play, it's the player. It comes down to just how you play, not the scheme. It's just how bad you want it. At the end of it, I felt like we just wanted it more."
Walsh threw a 20-yard TD pass to John Goodlett in the third quarter and a 44-yarder to former high-school teammate Josh Stewart in the first half.
"When the coaches draw plays up, we've got to execute them as best we can," Walsh said. "When we do, we're successful. And when we don't, we're not. I think as a whole we played really well tonight."