The Terrapins baseball team was in trouble.

Coach John Szefc’s squad trailed by five runs entering the fifth inning of its rubber match against Rhode Island on Sunday. And after the Terps offense recorded just four hits in its first two games in the series, it didn’t look promising.

But that’s when the offense exploded. First baseman Kevin Biondic smacked a two-run home run and designated hitter Nick Cieri blasted a grand slam in the fifth inning to give the Terps an 8-7 lead as the dugout emptied on each occurrence and fans cheered on their feet.

The Terps added two more runs in the inning and rode that momentum the rest of the game, as they defeated the Rams, 13-10, at Bob “Turtle” Smith Stadium, claiming their first series win of the season.

Eight Terps (3-3) recorded hits in the victory. But Rhode Island (1-5) held the momentum early, as it got to right-hander Brian Shaffer in the third inning.

Freshman right-hander Cameron Enck replaced Shaffer, but he struggled too, allowing a single and a walk to load the bases. Right-hander Ryan Selmer recorded the final two outs of the inning, but not before catcher Chase Livingston scored to for Rhode Island’s fourth run of the inning — all charged to Shaffer.

Catcher Justin Morris responded in the bottom of the inning with his first home run of the season to cut the Terps’ deficit to 4-2. In the fifth inning, the Rams extended their lead on a three-run home run from Livingston.

Szefc’s squad answered again, though, as the Rams fell apart in the fifth inning. The Terps recorded eight runs against three different pitchers in the frame.

In the Terps’ win against Alabama last Saturday, Szefc’s team belted three home runs. But the Terps set a new season high with four home runs Sunday when center fielder Madison Nickens drove a solo shot over the fence in the fifth inning.

It marked the first time the Terps have hit four home runs in a game since 2014.

While the Terps kept racking up runs, the Rams didn’t go away.

The Terps surrendered three runs in the eighth inning, which trimmed the Terps’ lead to 11-10. But shortstop Kevin Smith and second baseman Nick Dunn added runs in the bottom of the eighth inning to seal a victory in the Terps offense’s best performance of the year.