COLLEGE PARK, Md. (AP) Up and down the field they went, Indiana and Maryland in a duel to see which team would outlast the other.

After accumulating 828 yards and 53 first downs, attempting 78 passes and running 153 plays, the Terrapins and Hoosiers finally walked off the field Saturday after a game that lasted nearly four hours and ended with Maryland celebrating a 42-39 victory.

''Everyone was jumping up and down, the music was playing,'' Terps quarterback Max Bortenschlager said of the locker room scene. ''It was an awesome feeling.''

Bortenschlager threw two touchdown passes, Jake Funk ran for a pair of fourth-quarter scores and Maryland outlasted Indiana to keep the Hoosiers winless in the Big Ten.

''There was a lot of back and forth, a lot of momentum swings,'' Terrapins coach DJ Durkin said.

Maryland (4-4, 2-3) trailed 33-28 before rallying to snap a three-game losing streak. The comeback began with an 82-yard kickoff return by Javon Leake, and Funk put the Terrapins in front for good with a 1-yard touchdown with 14:56 remaining.

Funk scored again from the 1 with 10:14 left after Bortenschlager connected with DJ Moore for a 44-yard completion to the Indiana 17.

Indiana (3-5, 0-5) cut the gap to 42-39 but came up short in its bid to provide first-year coach Tom Allen his initial conference victory.

''Very disappointing loss for us,'' Allen said. ''It hurts our guys because the offense played well enough for us to win. Special teams prevented that, as well as some costly defensive mistakes, which has not been characteristic of us.''

The Hoosiers had a punt and an extra point blocked and yielded that game-changing kickoff return to Leake. The defense couldn't handle the fleet-footed Terrapins, who got 98 yards rushing from Ty Johnson and 77 pivotal yards receiving from DJ Moore.

''I'll be transparent: What they do stresses our athleticism in spots,'' Allen said. ''Their speed makes it hard on us. I'm just being honest.''

On offense, Indiana got the most out of both its quarterbacks. Peyton Ramsey went 31 for 41 for 279 yards and three touchdowns, and backup Richard Lagow passed for 131 yards and two scores.

Ramsey was flattened by a late hit in the third quarter and returned the following series, but Lagow ran the offense for much of the fourth quarter after Ramsey was felled again.

''If he was 100 percent healthy then we're going with him,'' Allen said of Ramsey. ''When he wasn't, we weren't going to put him in that position.''

Simmie Cobbs had 10 receptions for 138 yards and two TDs, Whop Philyor caught 13 passes for 127 yards and Luke Timian had 13 catches for 91 yards.

Indiana lost despite outgaining Maryland 483-345 and making 35 first downs.

Maryland didn't play much defense, but safety Darnell Savage set up a touchdown with an interception and scored on a punt he blocked .

Early on, Indiana dominated. The Hoosiers moved 75 yards on their first possession, taking a 7-0 lead on Ramsey's 34-yard touchdown pass to Cobbs.

Maryland's opening drive ended on its second play - an interception by Tony Fields. Ramsey followed the turnover with a 23-yard pass to running back Cole Gest, who bulled through a potential tackler on his way to his first career touchdown.

After Savage's interception set up a touchdown run for Lorenzo Harrison and the punt block made it 16-14, Ramsey connected with Timian for a score before Maryland scored two TDs in the final three minutes of the half.

MELLOW YELLOW

Maryland celebrated the 125th birthday of the football program by wearing throwback uniforms consisting of yellow helmets, yellow jerseys and black pants.

THE TAKEAWAY

Indiana: The Hoosiers thought their strong suit was defense, but that wasn't the case in this one. The rebuilding process under Allen appears to be working, though it's going to be a while before the Hoosiers can complete with the Big Ten elite, given that Maryland was difficult to handle.

Maryland: The Terrapins showed something in this victory, especially after falling into a 16-7 hole. Maryland may not be able to hang with the big boys in the Big Ten, but this was a satisfying win by a team using a quarterback who began the season as a third-stringer.

UP NEXT

Indiana: The Hoosiers host No. 5 Wisconsin (8-0, 5-0), which breezed past Illinois 24-10 on Saturday and beat Maryland 38-13 last week.

Maryland: The Terrapins visit Rutgers (3-5, 2-3), which had its two-game winning streak snapped by Michigan on Saturday.

---

More AP college football: http://collegefootball.ap.org and https://twitter.com/AP-Top25

Copyright 2017 by STATS. Any commercial use or distribution without the express written consent of STATS is strictly prohibited.