Playing with the desperation Ohio State needed to save its season, the Buckeyes came up with the rally for the ages.

J.T. Barrett completed a 16-yard touchdown pass to tight end Marcus Baugh with 1:48 left to lift Ohio State to an improbable 39-38 victory over No. 2 Penn State in front of 109,302 pleasantly stunned fans at Ohio Stadium.

Barrett completed his final 16 pass attempts to lead the Buckeyes (6-1, 5-0 Big Ten East) back twice from 18-point deficits. He finished 33 of 39 for 328 yards and four touchdowns.

Ohio State now is in the driver’s seat for a spot in the Big Ten championship game and remains quite alive in the College Football Playoff. The first playoff rankings will be released Tuesday night.

The Buckeyes had to fight uphill from the start, when Penn State’s Heisman Trophy front-runner — at least until now — Saquon Barkley returned the opening kickoff 97 yards for a touchdown.

Penn State (7-1, 4-1) led 21-3 and 28-10. Ohio State looked to have gotten a needed break when Denzel Ward was ruled to have intercepted a pass in the end zone while wrestling with DeAndre Thompkins in the third quarter. But after review, Thompkins was ruled to have had possession for a touchdown and 35-20 lead.

Ohio State pulled within 35-27 with 11 minutes left after Denzel Ward blocked a Penn State punt and Barrett connected with Johnnie Dixon on a 38-yard touchdown pass.

Penn State answered with a 10-play drive that included a third-and-13 completion to kick a field goal that returned it to a two-score margin. But Ohio State closed to within 38-33 with 4:20 left on another touchdown pass from Barrett to Dixon, this time a 10-yarder after a Penn State pass interference penalty. Dixon’s two-point conversion run failed.

The Buckeyes defense forced a three-and-out, giving Ohio State the ball back after a 57-yard punt at its 42. Barrett threw to Terry McLaurin and K.J. Hill for first downs to set up the pass to Baugh in the end zone for the go-ahead score.

Barrett was stuffed on the two-point conversion, but the Buckeyes’ defense swarmed Penn State quarterback Trace McSorley into three incompletions and a sack to clinch the win.

The game could not have started more disastrously. Barkley took the opening kickoff near the left corner as Ohio State wants it, cut left and got a couple of blocks. Kicker Sean Nuernberger was the only Buckeye with an angle, but Barkley easily outran him and went untouched for the 97-yard touchdown.

That cast an immediate pall on the Ohio Stadium crowd, but it would get worse. Parris Campbell fumbled after making a catch and Penn State recovered and returned it to the OSU 23. On third-and-goal from the 13, McSorley lobbed a pass to DaeSean Hamilton, who caught the ball over Damon Arnette in the back corner of the end zone for a 14-0 lead.

Ohio State scored on its third possession on a Nuernberger field goal after the Buckeyes stalled at the Penn State 13. It was the first time all year that the Nittany Lions have given up a point in the first quarter.

Penn State had its first sustained offensive drive of the game to make it 21-3. Barkley capped an 81-yard drive with a 36-yard run in which he slipped Buckeye tacklers near the line of scrimmage and bounced left for the score.

Ohio State countered with a five-play, 63-yard drive that ended when Barrett hit Terry McLaurin for a 14-yard touchdown pass to make it 21-10. It was the 91st touchdown pass in Barrett’s career, breaking Drew Brees’ Big Ten record.

But the Buckeyes’ self-inflicted wounds continued. Baron Browning was called for being offside on the ensuing kickoff. On the rekick, Ohio State had Koa Farmer hemmed in on a pooch kick — the Buckeyes weren’t going to kick in Barkley’s direction again — but overpursued. Farmer cut right and ran 59 yards to the Ohio State 23.

Even so, it appeared the Buckeyes would dodge that sequence when safety Damon Webb intercepted a pass in the end zone. But cornerback Damon Arnette was called for interference on Brandon Polk, which drew the ire — justifiably — of the crowd.

On the next play, McSorley ran 6 yards for the touchdown to make it 28-10. The Buckeyes got a needed touchdown with 5 minutes left before halftime on a 75-yard drive. Barrett did most of the work before Weber scored from 2 yards out after a pass-interference call on Penn State.