SANTA CLARA, Calif. - The San Francisco 49ers got Frank Gore involved in the offense again, and it returned them to their winning ways.
Hard-nosed defense helped, too.
Gore caught a career-best 55-yard touchdown and ran for 119 yards in his first 100-yard game of 2014, leading the San Francisco 49ers past Philadelphia 26-21 on Sunday to hand the Eagles their first loss.
The 49ers (2-2) avoided their first three-game losing streak under fourth-year coach Jim Harbaugh, containing the league's top passer. Nick Foles threw two incomplete passes from the 1 in the waning moments after gaining six first downs a lengthy drive, more than the five the Eagles managed before that.
Foles completed a 22-yard pass to Jeremy Maclin on the right sideline on that late drive. The 49ers challenged whether he had possession, but the play stood, costing the 49ers their final timeout.
The Eagles couldn't pull off the second-half magic that had carried them in their three wins.
On a day the 49ers gave up big plays on special teams, Gore delivered. Colin Kaepernick also threw a touchdown pass to Stevie Johnson and Phil Dawson kicked three field goals — two of at least 46 yards. Kaepernick finished 17 for 30 for 218 yards, two TDs and four sacks.
Darren Sproles had a career-best 82-yard punt return for a touchdown, Malcolm Jenkins ran an interception 53 yards for a score for the Eagles (3-1). Brad Smith recovered Trey Burton's blocked punt against Andy Lee for a TD.
The 49ers produced in the second half for the first time this season to give Harbaugh a win against former Pac-10 foe Chip Kelly.
Antoine Bethea intercepted his first pass with the 49ers and forced a fumble, then the secondary kept the pressure on in the red zone. Perrish Cox made an interception with 41 seconds left to seal it.
Gore's long scored from an off-balance throw by Kaepernick on the first play of the second quarter was the longest TD catch by a running back this season.
But on San Francisco's next series, Kaepernick threw right to Jenkins and he broke three tackles on the way to the end zone.
The 49ers won their first game at new Levi's Stadium, where thousands of fans skipped out at halftime.
San Francisco outgained the Eagles 232-73 in the first half, but still trailed 21-13. Then Johnson tiptoed both feet inbounds inside the left pylon in the third quarter for a 12-yard catch, the first second-half TD of the year for San Francisco, outscored 52-3 after halftime in its first three games.
Dawson kicked a 51-yarder before halftime, but the NFL's most-penalized team hurt itself with seven more flags for 60 yards in the first half and 10 total for 80 yards. The Eagles also had 10 penalties for 70.
San Francisco right tackle Anthony Davis made his season debut but went down on the final play of the first quarter when Kaepernick took a sack right into the back of Davis' left knee. Tight end Vernon Davis was sidelined with a back injury early in the third quarter; he missed last Sunday's loss at Arizona with a hurting left ankle.
Foles, who led the NFL in passer rating a year ago, was 21 for 43 for 195 yards and two interceptions.