NEW BRITAIN, Conn. – The outlook was bleak for the Portland Sea Dogs midway through the game Saturday night against New Britain.

Starting pitcher Casey Kelly was holding his own, but the Sea Dogs were down four runs because of defensive mistakes and leaving runners in scoring position while hitting into three double plays.

But the Sea Dogs played through it to get back on the winning track.

Portland sent 12 batters to the plate in a six-run seventh inning en route to an 8-5 victory over the Rock Cats before a franchise-best crowd of 8,497 at New Britain Stadium.

“The guys hung in there well and played nine innings tonight,” Sea Dogs Manager Arnie Beyeler said. “It would have been easy for us to fold our tents up.”

Portland (37-36) snapped a five-game losing streak and improved to 7-1 at New Britain this season. The Rock Cats (20-54) now are 8-29 at home.

New Britain starter Deolis Guerra allowed just one run through six innings and got the first out of the seventh when the deluge began.

A double by Ryan Khoury, a walk to Will Vazquez and an error by third baseman Yancarlos Ortiz filled the bases. Nate Spears’ two-run single brought on Cole DeVries (1-4).

Ray Chang tied the game with a double, Luis Exposito singled and Anthony Rizzo drove in the go-ahead runs with a double.

“The guys did a great job keeping the line moving, going up, getting a good pitch to hit and hitting the ball hard,” Beyeler said. “They didn’t chase (pitches) and made their guys work. We were fortunate enough to drive some baseballs, and the hitting stuff is contagious.”

Santo Luis (5-1) pitched 21/3 scoreless innings, yielding a hit and a walk while striking out three. Bryce Cox tossed 12/3 innings for his ninth save in 11 opportunities, although he walked two with two outs in the ninth.

“It was kind of a bend-but-don’t-break kind of a thing,” Beyeler said. “After the circus early, we played a little defense behind them.”

Kelly breezed through the first inning with two strikeouts, but struggled through the second.

With one out, Joe Benson drove a 3-2 pitch off the right-field wall for a triple, and Kelly’s command began to suffer.

Benson streaked home on a wild pitch, Steve Singleton doubled down the left-field line, Jair Fernandez was hit by a pitch and both advanced on another wild pitch.

Singleton scored on Mark Dolenc’s grounder to short, and Ortiz delivered Fernandez with a single to give the Rock Cats a 3-0 lead.

Kelly allowed six hits and four earned runs in five innings. He walked none and struck out six.

“He did a nice job,” Beyeler said. “He worked ahead. They were swinging at first-pitch fastballs and they squared some balls up, but you like guys who are aggressive.

“If we made some plays and helped out defensively, it would have given the game a different complexion.”