The Terrapins baseball team’s offense had lost some confidence.

After stranding 18 runners on base in its series loss against Alabama on Feb. 19-21, coach John Szefc’s squad recorded just four hits in each of its first two games against Rhode Island this past weekend. Behind strong pitching performances, though, the Terps were able to split the contests before entering the rubber match Sunday.

Through the first four innings Sunday, the Terps’ offense continued to struggle, and it didn’t have the luxury of strong pitching to support it this time. The Terps faced a 7-2 deficit entering the bottom of the fifth inning.

That’s when the offense exploded for the first time in the series. Behind two home runs ­— including a grand slam — the Terps scored eight runs in the inning to take a 10-7 lead.

The Terps won the decisive contest, 13-10, at Bob “Turtle” Smith Stadium, scoring double-digit runs for the first time this season to claim their first series victory.

“From the mental standpoint, this was a really good win,” Szefc said. “It was even bigger because at the time, the attitude was not good. Guys are still trying to think they’re good. All of a sudden, you go down five and you’re just like, ‘Geez, man, you’re like climbing a mountain here.’ Then all of a sudden you get a couple knocks.”

While the offense struggled and the pitching staff thrived Friday and Saturday, it was the opposite Sunday. The Terps (3-3) allowed 11 hits and turned to the bullpen early after right-hander Brian Shaffer surrendered four runs through 2.1 innings.

On Friday, right-hander Mike Shawaryn allowed just one hit over eight scoreless innings in a 1-0 win against the Rams (1-5). While the All-American pitcher commanded the strike zone, the Terps recorded just four hits, all of which came from the top three players in their batting lineup.

It was a similar situation Saturday. Right-hander Taylor Bloom struck out nine and allowed one earned run over seven innings, but the Terps recorded just four hits again in the 2-1 loss.

But after falling behind Sunday, first baseman Kevin Biondic said the Terps weren’t nervous about making a comeback. Though the sophomore said he got down on himself after the offense struggled the past two games, assistant head coach Rob Vaughn preached to the offensive players to stick to their approach.

So, Biondic said, the offense didn’t change its tactics, and it jumped on fastballs for the first time in the series. By the end of the day, eight Terps recorded hits.

“The pitchers have done an outstanding job this season,” Biondic said. “We needed to pick them up a little bit today. That’s what good teams do. When the hitters are struggling, the pitchers pick us up, and when they’re struggling, we pick up the pitchers.”

The Terps recorded season highs in runs, hits (12), RBIs (13) and home runs (four) to win the decisive game in the series. It marked the first time the Terps have belted four home runs in a contest since 2014.

While the Terps offense put together its best statistical performance of the year Sunday, the pitching staff allowed more than five runs for the first time this season. The Terps could’ve been in danger of a blowout Friday and Saturday with that pitching performance, but it didn’t matter Sunday.

“It was good to have a little bit of a coming-out,” designated hitter Nick Cieri said. “Hopefully we can keep continuing that this week and into next weekend.”

Szefc said his team’s offense is talented, but it would take time to develop with the Terps only returning three players in the lineup who started at least 30 games last season. On Sunday, the Terps offense displayed that talent, putting up 13 runs after entering the contest with 13 through five games.

“It’s rare to give up three big innings like we did and still win a game,” Szefc said. “I’m just happy to see these guys have success and start feeling good about themselves. A game like this can really get you going offensively and as a team.”