The Terrapins men’s basketball team trailed No. 20 Pittsburgh by five points with 23 seconds remaining in Saturday night’s matchup when Dez Wells flipped the ball back to fellow guard Seth Allen, who rifled a deep three-point attempt from the right wing.

The Terps were trying to complete a comeback, and Allen was squared to the hoop for a shot that could have trimmed the Panthers’ lead to two points for the first time in the second half and sent the announced 17,202 at Comcast Center into a frenzy.

But the ball instead clanked off the back rim and Pitt guard Cameron Wright grabbed the ensuing rebound to essentially seal the Panthers’ 83-79 victory, marking the Terps’ latest disappointment in a season defined by setbacks.

The Terps (11-9, 3-4 ACC) improved on offense against Pitt (18-2, 6-1), shooting 48.1 percent from the field and cutting a 13-point deficit to four. In the end, though, they suffered their fourth loss in five games to drop below .500 in ACC play for the first time this season.

“You think every shot is going in when a good shooter is shooting,” Wells said of Allen’s late attempt. “But it happens, man. It’s a part of basketball.”

There were still plenty of positives for coach Mark Turgeon to draw from. Wells had 19 points to lead four different Terps in double figures; the team scored 38 points in the paint against a stout Pitt defense, and the Terps shot better than 40 percent from the field for the first time since Jan. 4.

Still, the team turned the ball over 17 times and Turgeon criticized his team’s ball-screen defense for the second straight game.

Pitt often used picks to free up forward Lamar Patterson, who tallied a game-high 28 points. Plus, the Terps repeatedly sent the Panthers to the free-throw line, where they shot 32-of-47.

“We made some mistakes in our ball-screen defense,” Turgeon said. “We didn’t adapt and we forgot that Patterson was a pretty good player.”

Patterson scored 13 first-half points to bring his team back from an early 11-4 deficit and build a five-point halftime edge. The Terps, though, countered with their own balanced and cohesive offense that had been nonexistent in recent weeks.

“We just executed better, and we didn’t shoot so darn fast,” Turgeon said.

The offense kept the Terps within striking distance. Wells, Layman (18 points), guard Nick Faust (13 points) and forward Evan Smotrycz (10 points) all shot at least 50 percent from the field as the team became just the third Pitt opponent to post more than 70 points this season.

“We shared the ball great today,” Layman said. “We got a lot of great shots, great opportunities for our bigs and our guards to take some good drives.”

The Terps did go through a rough stretch, however. They coughed the ball up three times in the first five minutes of the second half, and Pitt took advantage by building a 13-point lead with 11:46 to play.

Unlike the last time they met the Panthers, when the Terps crumbled down the stretch of a 20-point loss on Jan. 6, the team absorbed the blow. Its newly potent offense kept the score close and the Terps found themselves down just five late in the game, inching closer to their first victory against a ranked team.

“In some games when we face adversity, we let it slip away,” Layman said. “But tonight we faced a lot of adversity with them hitting some tough shots and we just kept fighting.”

The Terps never could put the finishing touches on their comeback. Whether it was allowing the Panthers to narrowly escape a defensive trap just when it appeared a turnover was imminent or Allen sailing his 3-pointer a bit long, the Terps failed to make a defining play in their late run.

And as a result, an improved offensive effort went for naught in an unsuccessful upset attempt that capped the Terps’ worst 20-game start to a season since the 1992-93 campaign.

“It’s one of those years,” Turgeon said. “That’s the way it’s bouncing right now.”