Porcello turned in his worst outing in nearly two months, allowing five runs -- four earned -- in 6 2/3 innings, but that didn't matter thanks to three-run homers from Ramirez and Shaw.
"Rick is in a very good place here in Fenway," Red Sox manager John Farrell said after the bats bailed out Porcello in the Boston Red Sox's 8-7 win over the Minnesota Twins on Sunday afternoon at Fenway Park.
Porcello (13-2) tossed 6 2/3 innings, giving up six hits and a walk while striking out eight to improve to 10-0 at Fenway this season.
Boston has won all 11 games Porcello has started at home this year.
Porcello had not surrendered five runs in a start since June 2 at Baltimore.
"You talk about dependable and reliable, he embodies that," Farrell added.
It was Ramirez's 13th homer of the season and fifth in five games. He had a trio of two-runs blasts Tuesday against San Francisco and hit a three-run shot Saturday.
Shaw's shot was his 12th of the year and fourth in July.
The Red Sox have homered in 15 consecutive contests dating back to July 4, second only to their 22-game homer streak from April 29 to May 22.
Boston (55-41) has a major-league-best 13-5 record in July despite back-to-back losses to Minnesota coming in.
The Red Sox remained 1 1/2 games behind Baltimore for first place in the American League East after the Orioles' win Sunday.
Juan Centeno drove in three runs and Byron Buxton and Kennys Vargas each had two RBIs for the AL-worst Twins (37-61), who managed a four-game series split with Boston.
"You've got a chance to come in here and potentially beat a really good team that's been playing well, three out of four," Twins manager Paul Molitor said.
Twins starter Tommy Milone (3-3) was roughed up for eight runs -- four earned -- on 10 hits while striking out four in 4 2/3 innings.
"Good hitting team obviously. Can't take that for granted," Milone said. "I felt like I was throwing the ball well. Just a couple (bad) pitches."
Centeno's two-run double in the second put Porcello on his heels, but Ramirez feasted on Milone's first-pitch changeup for his homer an inning later.
Max Kepler opened the fourth with a triple, and Vargas' ensuing groundout tied it.
Shaw's homer highlighted a five-run Red Sox fifth, which began with Dustin Pedroia's solo homer to left-center, his 10th long ball of the campaign.
Aaron Hill's hard-hit grounder zipped under Miguel Sano's glove into left for an error, scoring a run and putting a pair of runners on for Shaw.
Shaw blasted a 2-2 curveball from Milone into the Boston bullpen.
"Instead of a potential one-run deficit coming off the field, they turn in four extra runs and now you've got a mountain to climb," Molitor said.
Minnesota made a late charge as Buxton's single in the seventh plated a pair, and Vargas' sacrifice fly with the bases loaded in the eighth made it a two-run contest.
Red Sox reliever Junichi Tazawa fanned Eddie Rosario for the second out of the eighth, but Centeno's RBI single past a diving Shaw at first base brought the Twins within a run.
Tazawa struck out Buxton swinging to stop the bleeding.
Brad Ziegler threw a clean ninth for his first save with the Red Sox and his 19th of the season.
NOTES: Boston DH David Ortiz (rest) was not in the lineup. "One of two planned (days off) this week with David getting off his feet," manager John Farrell said. 1B Hanley Ramirez was the designated hitter. ... Red Sox RF Mookie Betts (right knee soreness) missed his second straight game. "Improved today, to the point of being potentially available late today," said Farrell, who anticipates Betts being in the lineup Monday. ... Minnesota C Kurt Suzuki was "sore," but available in an emergency, after taking a foul tip to the chin Saturday, manager Paul Molitor said. ... Boston recalled RHP Joe Kelly from Triple-A Pawtucket and optioned RHP Heath Hembree to Pawtucket after Saturday's game. ... Tigers RHP Justin Verlander (9-6, 3.74 ERA) opposes Red Sox LHP Drew Pomeranz (8-7, 2.83 ERA) Monday. Twins RHP Ervin Santana (3-8, 3.93 ERA) counters Braves RHP Lucas Harrell (1-2, 4.24 ERA) Tuesday.