Lovejoy tied it at 16:54 of the third with his first goal of the season, though he has three points in his past four games.
Nick Bonino won a faceoff in the Sharks zone, tapped the puck to Lovejoy, who shot it to the right corner.
Hiller stopped all 12 shots he faced in the first period, including several outstanding saves.
Perry gave the Ducks the early advantage with a shot into the upper right corner 5:56 into the game. Ryan Getzlaf gave him a terrific pass to set up the goal.
Niemi had a solid second period, allowing the Sharks to take the lead.
Couture tied the game at 4:16 of the second. He redirected a shot from Marc-Edouard Vlasic over Hiller's glove. The goal ended a season-long goal scoring drought for the center.
The Sharks took advantage of an poor pass from Hiller to score an easy goal midway through the period for the go-ahead goal.
Hiller came out of the net to clear the puck, but flared it to Marleau's stick, who played give-and-go with Joe Thornton and scored into an empty net at 10:13.
Havlat picked up a rebounded shot and tipped it into the net with less than a minute remaining to put the Sharks up 3-1 entering the final period.
Grant, playing in his first NHL game, scored his first goal with 7:10 remaining in the third to bring the Ducks within 3-2. The defenseman took a shot that Niemi blocked with his right shoulder but was unable to control as it flipped in the air behind him and into the net.
NOTES: Getzlaf recorded a point in his 10th straight game, his longest streak in four years. ... Sharks C Joe Thornton, who has 18 points in his past 16 games, took a puck to his left eye that required stitches. He continued to play. ... The Sharks and Ducks played the first of five games in their season series. It was their first meeting since March 27, a span of 249 days. ... Hiller went down for a few moments after teammate Kyle Palmieri accidentally hit him in the side of the head. ... Ducks F Dustin Penner has eight points in his past six games. ... Mike Brown recorded his first assist of the season and his second point.