DURHAM — At least the ending worked out for Duke.

“We’re not going to like the year,” coach David Cutcliffe said, “but we like the finish.”

A season that nearly went totally off the tracks concluded with a 27-17 victory against visiting Miami on Saturday at rainy Wallace Wade Stadium.

“We just got a win,” senior safety Dylan Singleton said. “There’s a lot of joy in the locker room. Nobody is thinking about ‘what if?’ ”

Even with a five-game losing streak dashed, Duke (5-7 overall, 3-5 Atlantic Coast Conference) is left out of the bowl mix.

“It felt good,” defensive end Chris Rumph said of the conclusion. “We hadn’t won in a month and a half.”

Duke scored two touchdowns in a three-minute span in the middle of the fourth quarter to go ahead.

Running back Deon Jackson’s 2-yard touchdown run with 9:37 remaining came before quarterback Quentin Harris threw to freshman receiver Jalen Calhoun, who was alone along the sideline, for a 49-yard touchdown play at the 6:55 mark.

“I was praying it wasn’t an overthrow,” Harris said.

Calhoun had gone eight games since his last scoring catch.

Duke went 3-3 in home games this year. The Blue Devils have defeated Miami in consecutive seasons for the first time, winning last year in a rainy game on the road.

This became rewarding for other reasons.

“Great to kind of see the resiliency of this group,” said Harris, who played in his final college game. “… The emotions of the win are kind of overpowering. A sweet taste on the way out.”

Harris went 10-for-24 for 156 yards.

Duke’s defense recorded a season-high nine sacks, including 3 ½ credited to Rumph. Miami was limited to 259 yards of total offense.

“Everyone has seen a team when things go bad let it get worse,” Cutcliffe said. “That effort was about pride. Boy, did our folks battle and fight and do what we needed to do to win a football game.”

The Hurricanes (6-6, 4-4) have lost two in a row and will await a bowl assignment.

Miami’s Cam’Ron Harris ran 8 yards for a touchdown on the second snap of the second quarter on a drive extended by a successful fake punt.

Two minutes later, Duke was ahead on Quentin Harris’ 24-yard run.

Duke’s AJ Reed booted his second field goal midway through the second quarter for a 13-7 lead.

Miami went back on top on Robert Burns’ 36-yard run with 2:26 left in the first half.

Miami stretched its lead to 17-13. K.J. Osborn’s 43-yard punt return to the Duke 14-yard line in the third quarter set up Camden Price’s 27-yard field goal.