Four goals came in the third period. First, Anaheim pulled within one when Ondrej Kase stole the puck from behind the net and quickly fed Getzlaf, who fired it past Dell.
One minute later, the Sharks answered when Thornton's slap shot went in.
Boedker's second goal gave San Joe a 5-2 lead, and Karlsson's goal on goalie Ryan Miller made it a runaway.
The Ducks first found the net in the final minute of the second period, but that took a two-man advantage and a bit of luck.
Rakell was camped a few feet below the crease when he snapped a shot. San Jose's Justin Braun stuck out a stick, but it deflected the puck off the back of Dell's arm and into the net.
It was Rakell's team-high 17th goal this season.
San Jose appeared to take a commanding 3-0 lead on a power play in the second period. Boedker fired a shot from the top of the right circle that whistled past Gibson.
The Sharks took a 2-0 lead early in the second period when Anaheim's No.1 line turned the puck over. Thornton snapped it out to Labanc, who popped free for a breakaway. He beat Gibson on his short side for his fifth goal.
The Sharks took a 1-0 lead late in the first period on a nifty give-and-go when Tomas Hertl skated down the far side and sent a pass through the legs of Anaheim's Brandon Montour and right to Vlasic in front of the net.
Vlasic snapped it past Gibson for his seventh goal of the season.
Sharks: Return to San Jose on Tuesday night to play the Jets.
Ducks: Remain at home to play the Rangers on Tuesday night.
Veteran 49ers left tackle Joe Staley is expected to benefit from the Philadelphia Eagles’ trip to the Super Bowl.
Staley, originally chosen as an alternate, is expected to be named to his sixth Pro Bowl to take the place of Eagles Pro Bowl tackle Lane Johnson.
The Pro Bowl will be played Sunday, Jan. 28, in Orlando, Florida. Members of the Super Bowl participant Eagles and New England Patriots will not play in the All-Star game. The Eagles advanced to the Super Bowl on Sunday with a 38-7 victory over the Minnesota Vikings.
The other Pro Bowl offensive tackles representing the NFC are Dallas’ Tyron Smith and Los Angeles’ Andrew Whitworth, who replaced Washington’s Trent Williams.
Staley got off to a rough start last season as the 49ers opened on a nine-game losing streak. The idea of his career coming to an end began to creep into his mind, he said recently on the 49ers Insider Podcast.
But Staley said he had a talk with coach Kyle Shanahan that got him refocused for the remainder of the season. The 49ers finished with a five-game win streak to finish with a 6-10 record, and Staley played well down the stretch.
“I’m so far gone from where I was in that moment early in the year that I’m just focused on next year and, hopefully, years after that,” said Staley, 33, an 11-year NFL veteran. “I feel like I can still play.
“I think this last half of the season I played some of the best football of my career. I feel very confident in what we’re doing schematically with the people surrounding us, and it shows in my own play.”
Staley would join fullback Kyle Juszczyk, who was the only 49ers player named to the Pro Bowl when the teams were announced in last month.