MIAMI - Jose Fernandez's comeback required a comeback.

The precocious right-hander shook off a rocky start in his return from Tommy John surgery, pitching six innings and hitting a homer Thursday to help the Miami Marlins rally past the San Francisco Giants 5-4 and complete a three-game sweep.

The first two batters to face Fernandez scored, and he screamed at himself as he walked off the mound to end the first inning.

After that, Fernandez (1-0) found the form that made him the 2013 NL Rookie of the Year. Pitching in the majors for the first time since May 9, 2014, he allowed seven hits and three runs.

"I would have loved to have pitched a little better," he said. "But it's exciting I got the first one out of the way and we got a win."

Fernandez showed he still has a flair for the dramatic, hitting his second career homer to start the fifth and help Miami erase a 3-1 deficit.

"He thinks he's a hitter first," manager Dan Jennings said.

Justin Bour's three-run homer later in the inning put the Marlins ahead to stay less than 24 hours after he hit a walk-off homer to cap a come-from-behind win. The sweep was the first in a series of at least three games for Miami at home against the Giants since 1999.

Fernandez outpitched Matt Cain (0-1), who was also making his 2015 debut. Cain, sidelined last July by an elbow injury that required surgery, allowed five runs in five innings.

"It was probably one of the better days I've had feeling-wise, which is really a big positive," Cain said. "It's just now ironing it out and making good pitches."

Gregor Blanco homered against Fernandez, and Buster Posey also homered for the Giants.

Fernandez's hit and earned run totals were the highest for any of his 21 starts at Marlins Park. Even so, he improved to 13-0 at home, tying the modern record (since 1914) for home starts without a loss to begin a career, set by the Expos' David Palmer in 1979-84, according to STATS.

Fernandez topped out at 99 mph, and his final pitch was clocked at 97. His command was excellent, too — six strikeouts, no walks and 68 of 89 pitches for strikes.

"He had his normal stuff, it looked like," Giants manager Bruce Bochy said. "You don't expect to score a lot of runs off him. He looks healthy."

The crowd of 32,598 roared with every strike. Thanks to a giveaway promotion, Marlins fans were armed with masks of their ace's face.

Fernandez said he slept poorly in anticipation of the game, and was awake at 6 a.m. When he first took the field he was hit with a wave of emotion.

"I couldn't stop thinking about how life had given me another chance to be on the mound and do what I love," he said. "I almost teared up before I threw the first pitch."

He opened with a 94 mph fastball for a called strike, but the inning went downhill from there. Blanco singled and took third on a double by Joe Panik. Posey hit a sacrifice fly, and Brandon Belt's two-out bloop single scored another run.

"Jose was trying to be too fine, too perfect," Jennings said. "In the second inning he settled down."

Fernandez ended the fifth at 81 pitches, but Jennings let him bat to start the bottom of the inning. The .203 career hitter made the decision pay off with a homer than earned him a curtain call.

"I got lucky," Fernandez said.

He said his arm felt fine after the game. His next start is scheduled for July 9 at home against Cincinnati.

"I wish I could pitch tomorrow," he said.

ROSTER MOVES

Giants: As expected, RHP Tim Lincecum was placed on the disabled list retroactive to Sunday, allowing for Cain to be activated. Lincecum bruised his right forearm when hit by a line drive Saturday.

Marlins: To make room for Fernandez, the Marlins optioned RHP Jose Urena to Triple-A New Orleans.

TRAINER'S ROOM

Giants: Posey was back in the lineup after leaving Wednesday's game when a foul tip jarred his facemask. Posey started at 1B but was available as a backup C. ... OF Angel Pagan, who has been bothered by a swollen knee, was held out of the starting lineup on his 34th birthday. He pinch-hit in the eighth and struck out.

Marlins: Slugger Giancarlo Stanton was in uniform and in the dugout, his broken left hand in a cast.

CLOSER RESTS

Giants closer Santiago Casilla, who blew a save Wednesday, will be given two or three days off, Bochy said before the game. "It just didn't look like the same Casilla out there," Bochy said. "He's just a little tired, I think."

UP NEXT

Giants: RHP Jake Peavy, out since April 17 with a strained back, is scheduled to start Friday at Washington.

Marlins: RHP Tom Koehler (6-4, 3.66) is scheduled to start Friday against the Cubs at Wrigley Field.