The win was the second straight for BYU (8-3) over a Western Athletic Conference opponent.
Heaps made his first start since Sept. 30, when he was benched after the Cougars fell behind instate rival Utah State. Replacement Riley Nelson started the next five games but broke ribs and suffered a partially collapsed lung in last week's 42-7 win over Idaho.
Heaps finished 21 of 36 for 238 yards.
Matt Christian threw a second-quarter touchdown pass to Austin Franklin that tied the score at 7 for the Aggies (4-7), but also fumbled. Christian left the game in the third quarter because of injury. A fumble by replacement Travaughn Colwell set up another BYU score.
JJ DiLuigi led BYU with 75 yards rushing in his final home game.
A 2-yard TD run by senior Matt Marshall put BYU ahead 28-7 midway through the third quarter. It was the first carry of his career.
Heaps' third touchdown pass, a 9-yarder to senior Matt Edwards, gave BYU a 35-7 lead with 3:14 left in the third quarter.
Heaps' 27-yard TD pass to JD Falslev closed out the scoring.
The Aggies were coming off a 48-45 win over Fresno State in which they rolled up 500 yards of offense.
But BYU's defense came up with several big plays when needed.
BYU's defense set up the Cougars' first score after linebacker Jadon Wagner drilled Christian with a blind-side blitz, forcing a fumble. Senior Jameson Frazier recovered on the BYU 48 with 10:16 left in the first quarter.
Heaps drove the Cougars 52 yards in 12 plays, with Bryan Kariya capping the drive with a 4-yard touchdown run. Heaps completed two third-down passes to keep the drive alive.
After Christian left the game in the third quarter with an undisclosed injury, Preston Hadley and Wagner combined to sack Colwell and force another fumble, which Wagner recovered at the New Mexico State 40 with 3:48 left in the third.
Heaps had the Cougars in the end zone again three plays later.
The score was tied at 7 before a pair of touchdown passes from Heaps to Apo.
The first capped a 90-yard drive. Heaps swung the pass wide to Apo, who picked up a block from Marcus Mathews and scored from 20 yards out. The Cougars converted three third-down plays on the drive, with Heaps completing 12-yard passes to Cody Hoffman and Falslev and Kariya picking up 10 yards on a third-and-2 burst up the middle.
Heaps' second touchdown pass was a 9-yarder to Apo with 30 seconds left in the first half. Apo was hit at the 2 but stretched out for the score.
There was plenty of good from Heaps, but he also overthrew several wide-open receivers.
His eighth interception of the year set up the Aggies' first score as Donyae Coleman jumped a route by Mathews to give New Mexico State the ball at the BYU 38.
Heaps started the season as BYU's quarterback but struggled against the more difficult opponents. In his first four starts, he completed just 55.6 percent of his passes, with five interceptions and three touchdowns as BYU started 2-2.
The more mobile Nelson, a lefty, provided an instant spark, rallying BYU past Utah State and winning four of the next five, while struggling with two interceptions in a 38-28 loss at TCU.
BYU coach Bronco Mendenhall has said Nelson will get the starting job back when he returns, possibly in time for BYU's Dec. 30 bowl game. The Cougars earlier Saturday formally accepted an invitation to play in the Armed Forces Bowl against a Conference USA opponent.
BYU outgained New Mexico State 411-249, held a 173-90 edge in yards rushing and converted 10 of 14 third-down plays. The Cougars also were 6 of 7 in red-zone opportunities.
Kenny Turner led New Mexico State with 70 yards rushing on 16 carries.
Christian finished 12 of 23 for 98 yards and was sacked once. Colwell was 7 of 11 for 61 yards, with two sacks.
Apo led BYU with five catches for 66 yards.