BUFFALO, N.Y. – Christian Ehrhoff and the Buffalo Sabres haven’t had much success this season, but they can claim one thing: They know how to beat the Boston Bruins.

Ehrhoff scored the winner with 10:58 remaining and the Sabres rallied for three goals in the third period of a 4-2 victory over the Bruins on Friday night.

Both of the Bruins’ losses in regulation have come against Buffalo (6-8-1). The Sabres, who have won only four of their last 13 games, also won 7-4 in Boston on Jan. 31.

“They are a great hockey team,” said Ehrhoff, who also assisted on Cody Hodgson’s insurance goal with 8:15 left. “We were the better team in the third. As much as they outplayed us in the first couple of periods, we came out and played our game and turned the game around.”

Ehrhoff fired a wrister from the slot over goalie Anton Khudobin, who anticipated a low shot and went down early. Hodgson scored less than 3 minutes later when he tipped in a pass from Tyler Myers.

Myers began the comeback two minutes into the third period, tying the game at 2 by backhanding in a rebound after Khudobin stoned Jochen Hecht on a two-on-one break.

Buffalo goalie Ryan Miller described the importance of beating Boston, one of the front-runners in the Eastern Conference.

“It’s important for us to get points, but we recognize the rivalry and I know the guys recognize this as a measuring stick,” said Miller, who made 30 saves. “We go on the ice, we want to prove we belong.”

Drew Stafford also scored for Buffalo, which snapped a two-game skid and won for the third time in eight games.

Dougie Hamilton scored his first NHL goal and added an assist for Boston, which failed to earn a point for only the second time in 12 games.

Rich Peverley also scored for the Bruins. Khudobin stopped 22 shots.

Stafford opened the scoring 31/2 minutes in, breaking his 17-game stretch without a goal. He connected on a one-timer from the slot after a sharp feed from Tyler Ennis behind the net.

Hamilton connected on a slap shot from just above the right circle during a power play, becoming the first 19-year-old Bruins defenseman to score a goal since Jonathan Girard in 1999.

The rookie also accomplished it with a large number of family members and friends in attendance.

Hamilton grew up in suburban Toronto — about a 90-minute drive from Buffalo — and played his junior hockey for Niagara about 40 minutes away.

“To be able to do it in front of friends, and most importantly my parents, is a special feeling,” Hamilton said. “I wish it came in a winning game.”

Hamilton assisted on Peverley’s goal 2:29 into the second period, firing a shot off the back boards. A fortuitous bounce sent the puck directly to Peverley in the slot and he beat Miller on the stick side.

“A lot of shooting lanes are taken away, so we have to use the back boards once in a while,” Boston Coach Claude Julien said.

“We got a nice bounce on that, and guys were in the right position to jump on it and capitalize on it.”

With 8:15 left in the second period — during which Boston outshot Buffalo 17-6 — Miller was sharp on back-to-back saves, first stopping a long shot by Chris Bourque before foiling Tyler Seguin on a rebound from in close.