Eli Manning took a sip of a drink on the New York sideline, then slammed down the cup. Not in frustration, but in celebration.

Larry Donnell's spectacular catch over two 49ers with 21 seconds remaining lifted the Giants past San Francisco 30-27 on Sunday night, capping Manning's sensational clutch performance.

Manning had a career-best 41 completions in 54 attempts and his perfect throw to Donnell finished off an 82-yard drive with a 12-yard touchdown. He passed for 441 yards and became the winningest quarterback in team history with 102.

More from FoxSports

"This win is special," Manning said.

Donnell was between Antoine Bethea and NaVorro Bowman, two of the 49ers' best defenders, when he leaped to snag the pass in the back of the end zone before falling on his back, the winning catch secured.

New York (3-2) has won three straight and leads the NFC East. San Francisco (1-4) has lost four in a row and let this one slip away after an impressive comeback.

Carlos Hyde's 2-yard run with 1:45 remaining gave the 49ers the lead. But on a night of huge plays and lengthy drives, Manning and Donnell had the topper.

There were 20 plays of at least 15 yards in the game, and San Francisco had three on its late drive. Giants running back Shane Vereen had the last long play, a 24-yarder. And Manning, without his best weapon, Odell Beckham Jr., for much of the final series, engineered his 27th comeback victory in the fourth quarter or overtime.

"It ranks up there as far as comebacks," said coach Tom Coughlin, who passed Hall of Famer Paul Brown for 12th in career victories with 167. "They are resilient, tough-minded, they find themselves as a scrappy bunch.

"I told them in the locker room it took every guy, people were playing and pushed into roles that maybe they hadn't been in before. That's a real sign of a team."

Beckham's speed and moves were too much for the 49ers. He set up New York's first touchdown by using his elusiveness for a 31-yard reception down the middle. His 15-yard catch led to a 17-yard score on which he spun neatly and sped down the left sideline.

The touchdown was his last reception; he left with a hamstring injury, something that has plagued his short pro career, and returned only briefly on the winning series. Beckham finished with seven catches for 121 yards a week after he was fined for punching a Bills player in a win at Buffalo.

Anquan Boldin had eight receptions for 107 yards and a TD for the 49ers.

Both teams staged long drives all night. In an opening half filled with field goals, New York had possessions of 76, 81, and 66 yards, San Francisco had a 76-yard series. Aside from Vereen's 2-yard TD reception in the second quarter, though, it was all field goals. Josh Brown made 22- and 41-yarders for the Giants, and Phil Dawson countered from 43 and 22.

Manning forced an ill-advised pass for Beckham in the corner of the end zone that never had a chance and was picked off by Tramaine Brock to end the half. That kept the 49ers close, and they put together another long march, covering 88 yards in the third quarter, with Boldin sparking the drive on a 37-yard catch and run. He finished it with a 3-yard reception from Colin Kaepernick for a 13-13 tie.

Beckham gave the Giants the lead with his final heroics of the night, only to have San Francisco answer with an 80-yard drive helped by a 28-yard pass-interference call against safety Landon Collins. Garrett Celek capped it with a 5-yard reception.

Those lengthy series had become more fruitful in the second half, but the Giants had to settle for Brown's 24-yarder with 4:29 remaining for a 23-20 lead. He tied his team record with a 17th consecutive successful field goal, but it left room for the 49ers to rally.

And, ultimately, for the Giants to do the same.

New York also lost starting middle linebacker Jon Beason (concussion) and wideout Rueben Randle (hamstring). 49ers RB Reggie Bush was sidelined by a calf problem.