SAN FRANCISCO — Pete Alonso’s day off was less eventful than Ferris Bueller’s, but it created about as much havoc.

The Mets first baseman, who Saturday arrived in a slump and was deemed in need of rest, spent the first five innings on the bench before entering as a pinch-hitter in the sixth. And with a mighty swing he returned to the bench, having sent the Mets toward a runaway win over the Giants.

“I call it a mental health day,” Alonso said after smashing a three-run homer that helped the Mets end a two-game skid with an 11-4 victory at Oracle Park. “It was a great mental health day.”

Dominic Smith, Jeff McNeil and Todd Frazier also homered, allowing right-hander Walker Lockett to win his first major league game. Smith finished 3-for-5 with four RBIs.

The scoring outburst was welcomed by the Mets (45-53) after two straight extra-inning losses in which they played a combined 26 innings and scored only two runs.

Alonso entered Saturday in a 3-for-30 (.100) slump with two homers and 13 strikeouts, prompting manager Mickey Callaway to surmise he was tired following a return from the All-Star break that included his participation in the All-Star Game and victory in the Home Run Derby. Alonso was given the day off from the starting lineup, but with two runners aboard and two outs in the sixth, he pinch hit for Lockett and delivered his 33rd homer of the season, extending the Mets’ lead to seven runs. Alonso boosted his RBI total to 75, which broke the franchise rookie record established by Darryl Strawberry in 1983.

“I worked on some stuff during the game in the cage and kind of cleaned up some stuff,” Alonso said. “The best way to describe it was I was working on ‘aim small, miss small.’ I was working very finely and just focusing on good direction and getting the ball in the area I wanted. I was looking at too big of an area.”

Callaway had no complaints about the manner in which his first baseman handled his mental health day.

“That’s what you want: one at-bat, three RBIs and go rest again,” Callaway said.

Send us your MLB questions when you sign up for our Starting Lineup newsletter and our experts will answer their favorites leading up to the July 31 trade deadline.

Frazier gave the Mets a four-run cushion with the Mets’ third homer of the game, a solo blast in the sixth against Derek Holland. In the fourth, Frazier had tripled and scored on Smith’s ensuing single.

Smith homered leading off the second to give the Mets their first run. Saturday was something of a redemption day for Smith, who a night earlier dropped a pop-up in left field in the 10th inning that allowed the Giants to score the winning run.

“I talked to [Smith] before the game and he wasn’t happy about last night,” Callaway said.

But Smith could smile after his breakout Saturday.

“That’s just how baseball is,” Smith said. “You can’t get too high and you can’t get too low and I just wanted to turn the page from [Friday] night. Obviously I know I cost us the game and it’s something that none of us in here wants to do.”

McNeil swatted a two-run homer in the fifth that gave the Mets a 4-0 lead. After Amed Rosario singled leading off and stole second in the inning, McNeil lofted an 0-2 pitch from Jeff Samardzija off the right-field foul pole for his ninth homer of the season.

The victory guaranteed the Mets of a winning road trip, but it isn’t the same as the momentum they would have had if they pulled off wins the previous two nights in the extra-inning games.

“We’ve been playing well and the pitching has been doing their thing,” Smith said. “We weren’t able to get runs the last couple of days and we just wanted to help them out because they are carrying their part.”