With its starting quarterback watching from the sideline following a first-half injury, the Navy football team nearly completed an improbable comeback from a double-figure deficit behind backup Trey Miller, whose poise and steady arm had put the Midshipmen ahead of East Carolina midway through the fourth quarter Saturday in Annapolis.

But what would have been one of Navy’s more inspirational victories turned into another confounding loss, 38-35, when place kicker Jon Teague’s 42-yard field goal attempt clanked off the right upright as time expired. It marked a fifth consecutive loss for the Midshipmen (2-5).

Teague’s miss came two plays after wide receiver Matt Aiken momentarily had control of Miller’s 33-yard pass before the ball popped loose as Aiken hit the ground while crossing the goal line. The officials ruled the pass was incomplete.

Coach Ken Niumatalolo challenged the call but the officials upheld their ruling, taking away Navy’s final timeout. Aiken then caught an eight-yard pass on third and 10, and the Midshipmen rushed their kicking unit onto the field for the failed try.

Navy has now missed a field goal or extra point in four straight games.

The loss in front of 34,612 was Navy’s fourth this season by three points or less, adding more frustration to a season that began with bowl aspirations but now is in jeopardy of becoming the program’s worst in almost a decade. Last week, Navy lost by a point to Rutgers after, among other blown chances, Teague had a field goal blocked in the last five minutes. Two weeks earlier, a blocked extra point in overtime allowed Air Force to escape with a one-point win.

“This is a tough loss for this team and this program,” Niumatalolo said. “I thought we prepared well for it. I’ve been coaching a long time, and I can’t remember this many heartbreaking losses in a year.”

Miller led Navy on a rousing comeback soon after he was pressed into service when senior Kriss Proctor absorbed a late hit in the second quarter that damaged his left (throwing) elbow. After some early struggles, Proctor’s understudy — in just his second career game — grew considerably more comfortable down the stretch.

Trailing 24-14 with just less than 11 minutes to play in the third quarter, Miller rallied Navy with three touchdown drives, capping the run with a 37-yard strike to Aiken for a 35-31 lead with 7 minutes 51 seconds to play.

But East Carolina (3-4) marched 77 yards in 15 plays to take the lead for good when junior running back Reggie Bullock scored from three yards with 2:14 left. Navy got the ball back with 2:06 to go to set up the white-knuckle conclusion.

“Even when we are down, we will never give up,” senior defensive end and co-captain Jabaree Tuani said. “Kriss went down, and Trey came in. As a defense, we can’t put all of the pressure on him. We needed to make plays and help him out.”

The defense failed to make good on that when it mattered most, giving up two third-down conversions — Navy stopped just 6 of 17 for the game — and one on fourth and five during the Pirates’ winning possession.

The fourth-down play went for 11 yards on Dominique Davis’s completion to wide receiver Danny Webster and was among the many signature moments for the East Carolina quarterback, who completed his first 26 pass attempts to set an NCAA record. The previous record in one game was 23 in a row, shared by California’s Aaron Rodgers and Tennessee’s Tee Martin.

Davis finished 40 of 45 for 372 yards and two touchdowns and established another record with 36 consecutive completions dating from last week, the most consecutive passes completed over multiple games in NCAA history.

Miller, meantime, completed 5 of 12 passes for 126 yards and two touchdowns and had 13 carries for 36 yards. Junior slotback Gee Gee Greene led Navy with a career-high 92 rushing yards on eight carries and added a touchdown.

“This one is tough, it is hard,” Niumatalolo said. “They all have been. It is hard on the guys. They worked hard last week and practiced hard. I’m speechless for these guys. They have busted their butts. I want them to see some of the fruits of their labor.”