Ash directed the Longhorns (4-0, 1-0 Big 12) on a 75-yard scoring drive after the Cowboys (2-2, 0-1) had taken the lead on Quinn Sharp's 23-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-4 to keep the drive going, and then Mike Davis outleaped Justin Gilbert on a 32-yard deep ball to set up Bergeron's winning touchdown.
Ash finished with 304 yards passing. He also threw his first interception of the season.
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, who had lost at home to OSU each of the past two seasons, moved to a perfect 7-0 in Stillwater under coach Mack Brown. Texas also improved its record to 23-4 in a series that has featured comebacks from 28-, 19- and 21-point deficits just since 2004.
This was another difficult one 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 2-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-yard line. 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.
Sharp's field goal put the Cowboys back on top -- but there was just enough time for Ash to lead the Longhorns back.
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.
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.
Walsh rallied Oklahoma State with a 20-yard TD pass to John Goodlett at the tail end of the third quarter to start an Oklahoma State rally and set up the fourth-quarter theatrics.
Walsh also had a 44-yard TD pass to former high-school teammate Josh Stewart in the first half.
Oklahoma State outgained Texas 275-136 on the ground, but the Longhorns were able to produce enough when it counted.
With Lunt on the sideline in his jersey but no shoulder pads, Oklahoma State still came bursting out of the gates.
Randle took a handoff on the second play of the game, zoomed through a huge hole and shed a tackle attempt by Adrian Phillips on his way for a 69-yard touchdown run. Phillips also missed a tackle on Stewart's 44-yard touchdown catch as the Cowboys tied it at 14.
D.J. Monroe ran back the ensuing kickoff, dodging two diving tackle attempts by Oklahoma State players and racing 100 yards for the go-ahead score.