A third freshman, Josh Quezada, ran for 107 yards and a touchdown as the Cougars (6-5, 5-2 Mountain West) won for the fifth time in six games despite committing 14 penalties.
Stump Godfrey threw for 125 yards and a touchdown and added 53 yards rushing for New Mexico (1-10, 1-6).
Heaps threw a 17-yard touchdown pass to Hoffman in the third quarter and a 10-yarder in the fourth quarter. Heaps finished 18-of-32 for 231 yards.
Mitch Payne made two field goals and four extra points to become the Mountain West career leader in kicking points with 314, two more than his brother Matt had for BYU.