Stafford scored on a slap shot 8:06 into the third period to give the Sabres a 3-1 lead and they held on to win for the third time in four games this season.
Jhonas Enroth stopped 13 shots in the third period and made 30 saves overall to get the victory. He allowed Jordan Staal's backhander to get past him with 4:51 to play that brought the Penguins within one.
Pittsburgh had not lost to Buffalo at home in almost three full seasons and had swept the four games against the Sabres last year.
Gerbe scored 9:24 into the game and Luke Adam added a goal to give the Sabres a 2-0 lead after one period.
Marc-Andre Fleury took the loss while stopping 25 of 28 shots.