Miller stopped 33 shots, including the first 16 he faced, to earn his 30th win of the season in his first game back after missing 13 because of a sprained left ankle.
But Gaustad, with the goal with 9:04 left, halted a three-goal rally by the Maple Leafs after the Sabres raced to a 4-0 lead.
"They smelled blood and wanted to get back on the attack," Miller said. "We did a good job not panicking and getting pucks to the net. We were definitely rewarded with [Gaustad's] goal."
"We've been talking about getting pucks to the net and it paid off," Gaustad said. "We showed confidence and poise and went back at them."
The win set up a key Eastern Conference playoff showdown Saturday, when Buffalo travels to face Montreal. With 80 points and eight games left, the Sabres are 10th in the East, five points behind Montreal, which holds the eighth and final playoff spot.
"You have to win every game," Sabres defenseman Jaroslav Spacek said. "For us, every game's big. You have to play really smart, win the battles and keep it simple, especially in the beginning."
Buffalo came out strong against Toronto goalie Curtis Joseph, scoring four goals on nine shots and chasing the veteran 3½ minutes into the second period.
"You have to find a way to bring your best every night, and tonight wasn't my night," Joseph said. "We did battle back, no question. I thought we would make a great comeback, but it was a little too late."
Boyd Devereaux and Matt Stajan had a goal and assist each for the 11th-place Maple Leafs, who lost for only the second time in six games (4-2-0) and are all but mathematically eliminated from contention. Nikolai Kulemin also scored for Toronto.
Miller had little support on the three goals he allowed -- including Kulemin's that came during a scramble in front and after Miller made a diving stop to foil Alexei Ponikarovsky.
"We didn't really give up a lot although they got back in it," Buffalo coach Lindy Ruff said. "I still thought we played our game."
There was also no question about who would play in goal for the Sabres against the Canadiens.
"Miller will play," Ruff said. "I don't think there's any secret there."
"It felt pretty good throughout the whole night," Miller said. "I'll throw some ice on it tonight, see how it feels and go back at it."
Gaustad's goal, scored less than 3 minutes after Stajan and Kulemin scored 43 seconds apart to cut it to 4-3, came after a clearing attempt by Toronto's Ian White bounced off Gaustad and past rookie backup goalie Justin Pogge.
Miller, meanwhile, showed little signs of rust or effects of his injury, and was particularly sharp in the first period, when he made 14 saves, including two on bang-bang chances by Stajan from the right circle.
The same could not be said for Joseph, who was yanked after Paille and Connolly scored 21 seconds apart.
Joseph earned his 351st career loss to move to within one of matching Gump Worsley's NHL record.
- Joseph is tied for second in career losses with Gilles Meloche, but also ranks fourth with 453 career wins.
- Sabres D Craig Rivet missed some action after leaving three minutes into the third period. He was struck in the right cheek by Devereaux's weak shot from the high slot.
- Leafs RW Niklas Hagman missed his 13th game with a concussion, but has a chance to return as soon as Saturday, when Toronto hosts Boston.
- Joseph started in place of Martin Gerber, who received an automatic three-game suspension from the NHL for abusing referee Mike Leggo in a 3-2 shootout win over Washington on Tuesday night.
- Connolly now has 16 goals this season, matched his personal season best set in 2005-06.