EAST RUTHERFORD, N.J. -- In each of their first two games this season, the New York Giants found ways to lose in the final minutes.
On Sunday night, they flipped the script to move above .500.
Giants quarterback Eli Manning engineered his 27th career game-winning, fourth-quarter drive, connecting with tight end Larry Donnell on a 12-yard touchdown pass with 21 seconds left, giving New York a 30-27 victory over the San Francisco 49ers.
"That was some football game tonight," Giants coach Tom Coughlin said.
"Hats off to Eli Manning and the New York Giants," 49ers coach Jim Tomsula said. "We didn't make enough plays."
The 49ers, who trailed 13-6 at the half, scored 21 points on touchdown passes by quarterback Colin Kaepernick to wide receiver Anquan Boldin and tight end Garrett Celek, plus a 2-yard carry by running back Carlos Hyde, each of those scores capping drives that spanned at least 80 yards.
Hyde's touchdown with 1:45 to play put San Francisco on top 27-23.
"It's good offensively to get in a rhythm like that, but we have to win games," Kaepernick said. "That's why we play."
The Giants, even with top receivers Odell Beckham Jr. and Rueben Randle missing chunks of the second half due to hamstring strains, found a way to get it done.
Manning, who finished 41 of 54 for 441 yards and one interception, connected on two of his three touchdown passes in the second half. He threw a 17-yard scoring pass to Beckham late in the third quarter, prior to the receiver exiting the game with a hamstring injury, and the game-winner to Donnell, the tight end's second touchdown catch of the year.
Donnell's game-winning catch was extra special for the Giants, who dedicated the win to tight end Daniel Fells, who is currently hospitalized due to a MRSA infection after being placed on season-ending injured reserve last week.
"Thank God we were able to give him the game ball," Coughlin said. "To have a guy from his (tight end) room go up there and make that catch at the end of the game was just incredible."
New York (3-2) increased its grip on first place in the NFC East. The Giants will visit the Philadelphia Eagles a week from Monday with an eye toward avenging last year's embarrassing 27-0 loss, which also took place in front of a national television audience.
The 49ers (1-4) lost their fourth in a row. They head home to host the Baltimore Ravens next Sunday in desperate need of a win, and more determined than ever, according to their quarterback.
"To me, there's still 11 more games," Kaepernick said, "We have an opportunity to go 12-4. We have to get on that path."
The Giants led 13-6 at halftime, with Beckham catching five passes for 89 yards. He finished with 121 yards on seven catches, the ninth time in his career that reached triple figures in receiving yards.
Boldin made eight catches for 107 yards. Hyde gained 93 yards on 21 carries, and Kaepernick was 23-for-35 for 262 yards and two touchdowns with no interceptions.
Two of Beckham's longest receptions in the half were directly responsible for New York's first 10 points.
His first was a 49-yard grab that set up the first of kicker Josh Brown's two field goals to knot the game at 3-3.
Beckham made a 31-yard catch to set the stage for running back Shane Vereen's 2-yard touchdown reception, his first score as a Giant, to make it 10-3. Vereen wound up with eight catches for 86 yards and five carries for 24 yards.
The 49ers' only points of the half came on their opening and final drives of the half, both field goals by kicker Phil Dawson.
On the first drive, Kaepernick was 2-for-2 for 39 yards, including a 30-yard receiver screen to Bruce Ellington that pushed the ball deep into Giants territory.
Brown added his second field goal of the half, a 41-yarder, to give the Giants a 13-3 lead with 4:02 left in the half. San Francisco responded with a 22-yard Dawson field goal.
The Giants came close to extending their lead in the final seconds of the half, but Manning tried to force a pass to Beckham in the corner of the end zone, and it was picked off by safety Antoine Bethea for a touchback.
NOTES: Giants MLB Jon Beason was injured while tackling RB Carlos Hyde on the 49ers' opening possession. Beason was taken into the locker room, where he was diagnosed with a concussion. ... The 49ers had 115 passing yards in the first half, 66 of which came on three pass plays of 15 or more yards, including a 30-yard screen to WR Bruce Ellington, a 19-yard reception in the flat by FB Bruce Miller and a 17-yard catch by WR Torrey Smith. ... Giants TE Will Tye made his first NFL reception, a 12-yard gain that went for a first down late in the first quarter. ... With the win, his 167th in the regular season, Giants coach Tom Coughlin passed Hall of Famer Paul Brown for the 12th most regular-season victories in NFL history.