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 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.

Giants starting pitcher Matt Cain came back from the disabled list Thursday, starting in his first game in about a year. Cain’s comeback was rough, however. He went five innings, giving up five earned runs on seven hits, walking four. He gave up home runs to Fernandez and a three-run shot to Justin Bour.

The Giants have now lost three games in a row, and haven’t been swept in Miami since 1999.

The Giants head to Washington for a July 4 weekend series against the Nationals. Jake Peavy will return from the disabled list tomorrow to face the Nationals.