AP Sports Writer

MIAMI (AP) — 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 for the first time since May 9, 2014, he went six innings and allowed three runs.

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.

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.

A.J. Ramos pitched a perfect ninth for his 12th save in 15 chances. 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.

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

Fernandez gave up seven hits, and his 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.

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.

The crowd of 32,598 roared with every strike. And thanks to a giveaway promotion, fans were armed with masks of the pitcher's face.

Fernandez's first pitch was 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.

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

Later in the inning, Bour homered against the Giants for the third game in a row, putting Miami ahead 5-3.

   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.

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.

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.

Copyright 2015 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.

Join our Newsletter for the latest news right to your inbox