Gray had touchdown runs of 84 yards in the second quarter and 48 yards in the third. Von Miller intercepted a tipped pass at the Texas A&M 11-yard line with 2 minutes 37 seconds left to kill what looked like a drive for the tying touchdown.
Jeff Fuller also caught a touchdown pass and Randy Bullock kicked a 50-yard field goal for the Aggies (9-3, 6-2 Big 12).
Texas' fifth home loss of the season means the Longhorns (5-7, 2-6) won't be eligible for a bowl only one season after playing for the BCS title.
The Aggies won their sixth game in a row and still have a chance to win the Big 12 South if Oklahoma beats Oklahoma State on Saturday. The Aggies would still be a longshot for the Big 12 championship game because of a tiebreaker based on BCS standings.
Cody Johnson rushed for 107 yards for Texas. Garrett Gilbert was 20 for 37 passing for 219 yards.
Gray is the first Texas A&M running back to reach 200 yards since 1995.
Texas A&M scored 17 points off three Texas turnovers and led 24-14 after Gray's second touchdown. Texas kicked a field goal after a blocked punt and used a long drive to march toward a touchdown before Gilbert's pass was tipped at the line of scrimmage.
Miller, a defensive end who drifted back into coverage, leaped high to grab it.
Texas had never had a losing season under Coach Mack Brown but completely fell apart after quarterback Colt McCoy and a host of other players ended their careers.
One season after winning the Big 12, Texas finished dead last in the South Division.
Roger Federer and Andy Murray easily secured spots in the semifinals of the ATP World Tour Finals at London with straight-sets victories in their last round-robin matches.
Federer continued his dominance over Robin Soderling, beating the Swede, 7-6 (5) 6-3, to earn the top spot in Group B of the season-ending tournament. Murray followed up by recovering from a shaky start to beat David Ferrer, 6-2, 6-2, to hand the Spaniard his third straight loss in the group phase.
Their semifinal opponents will be decided Friday, when the last round-robin matches in Group A are played.
Federer won his third straight group match and improved his career record against Soderling to 15-1, with his only loss coming in this year's French Open quarterfinals.
Tournament director Craig Tiley released a statement saying Williams had pulled out of the Hopman Cup international mixed teams competition in Perth and the Australian Open.
It is the second consecutive Grand Slam tournament Williams will miss, and the loss of 2,000 rankings points could cost the 29-year-old star her place in the top 10.
Hollywood Park's annual three-day, Thanksgiving weekend Turf Festival will open Friday with the featured $250,000, Grade I Matriarch and end with Sunday's $250,000, Grade I Hollywood Der- by.
In between will be Saturday's Grade II Citation, also a $250,000 race; the $100,000, Grade III Generous Stakes; and Sunday's prelude to the Derby, the $100,000, Grade III Miesque Stakes.
The Matriarch, with Special Duty positioned to win for the fifth time in 10 races and expand on her purse total of $1,070,938, is one mile for fillies and mares, 3 years old and up. The Hollywood Derby, featuring the 22-1 stunning victor Fantastic Pick from the Oct. 16 Oak Tree Derby, will be 11/4 miles for 3-year-olds.
The Citation's distance is 11/16 miles for 3-year-olds and up; the Generous a mile for 2-year-olds; and the Miesque a mile for 2-year-old fillies.