Gahafer connected with Jake Raymond for a 17-yard score with 2:45 left and the Eagles took a 36-29 lead after a successful 2-point conversion.
Morehead State (6-4, 5-2 Pioneer Conference) moved above .500 for the first time since a 7-4 record in 2007.
Valparaiso (2-8, 1-6) rallied from a 21-7 deficit when Jarrett Morgan scored on a 1-yard touchdown run to make it 29-28 with 9:45 to play.
Raymond caught six passes for 88 yards and two touchdowns, and threw a 20-yard touchdown pass to Gahafer on a trick play that gave Morehead State a 14-7 lead. Gahafer was 27-of-55 passing with one interception.