IOWA CITY, Iowa (AP) — Purdue has struggled so much in recent weeks that it's easy to forget that it's the same team that nearly took down Notre Dame and Ohio State on the road.

The Boilermakers finally won a close one away from home on Saturday, snapping a miserable losing streak with three brilliant plays in a row.

Purdue drove 37 yards in 16 seconds and Paul Griggs drilled a 46-yard field goal as time expired as Purdue stunned Iowa 27-24, snapping a five-game losing streak.

Robert Marve threw for 266 yards and two touchdowns for the Boilermakers (4-6, 1-5 Big Ten), who won for the first time in Iowa City in 20 years.

"We knew that if we could get protection for our quarterback, that Robert Marve could be a difference maker," Purdue coach Danny Hope said.

Purdue, which lost 20-17 against Notre Dame and 29-22 in overtime at Ohio State, led 24-14 before Iowa (4-6, 2-4) rallied to tie the game with 3:32 left. But the Boilermakers stuffed the Hawkeyes on fourth down with 16 seconds left.

Marve then ran for 17 yards and found Antavian Edison for 20 more and set up Griggs to drill the longest field goal of the season by Purdue.

"Hats off to him to play the game with all the courage that he has," Hope said of Marve. "The last drive we didn't have any second guesses in our minds that if we could protect for Robert, we could kick a field goal."

James Vandenberg had 190 yards passing and a TD for Iowa, which has lost four straight for the first time since 2007.

"Clearly we were outcoached and outplayed," Iowa coach Kirk Ferentz said. "They were more ready to play emotionally, and more ready to play cleaner, more fundamentally sound. You can say it's this or that, lunar moon or whatever. But that's coaching, and that's me."

Iowa got the ball back with 1:08 left in a tie game and moved 52 yards in 52 seconds. But the Hawkeyes went for it on fourth-down-and-3 — with a strong headwind leaving a field goal as a long shot — and got just one yard.

Iowa has now played in six games decided by three points or less — more than any other team in the country — and has lost four of them.

The Hawkeyes were outgained 490 yards to 264, but three Purdue fumbles kept them in the game until the end.

Iowa pulled within 17-14 on Vandenberg's 5-yard pass to C.J. Fiedorowicz late in the third quarter. It was just Vandenberg's fifth TD toss of the season, and it helped brighten the mood of a frustrated home crowd.

The good cheer was short-lived.

Purdue's Ralph Bolden somehow stayed in bounds with nearly the entire Iowa defense flushing him to the sideline, tip-toeing 56 yards to set up Marve's 10-yard touchdown pass to Gary Bush to put the Boilermakers ahead 24-14.

But Iowa caught a huge break when Marve's fumble bounced into the arms of cornerback Micah Hyde, who returned it 9 yards to make it 24-21 Purdue heading into the fourth quarter.

The Hawkeyes tied it up at 24-all on a 24-yard field goal by Mike Meyer with 3:32 left.

Purdue opened the scoring with a 3-yard TD run by Akeem Shavers. The Boilermakers then fumbled the ball to Iowa on back-to-back plays — and Damon Bullock's 1-yard TD run tied the game at 7-7.

The Boilermakers quickly answered those mistakes with an 11-play scoring drive facilitated in part by terrible tackling on the part of the Hawkeyes — something they fought through all afternoon.

It took five minutes and ended with a 9-yard touchdown grab by Gabe Holmes that put Purdue ahead 14-7 with 4:43 left before halftime.

"The plays were out there to make, and we just didn't make them," Iowa wide receiver Jordan Cotton said.

The Boilermakers had a halftime lead for the first time since that loss in Columbus on Oct. 20 They did about all they could to give it back, but Marve and Griggs were clutch in the final 16 seconds.

Purdue can now become bowl eligible with wins over Illinois and Indiana. Iowa must beat Michigan and Nebraska to do the same.

The Hawkeyes ran for just 74 yards in 31 tries against the Big Ten's worst rushing defense entering play.

"They looked like the team that played against Ohio State and Notre Dame earlier in the year, so give them credit," Ferentz said.