Santa Clara, CA (SportsNetwork.com) - The San Francisco 49ers got back to their hard-nosed ways and figured out their second-half woes.
The 49ers stymied Philadelphia's potent offensive attack and had a late goal- line stand, holding off the Eagles 26-21 to hand them their first loss of the season on Sunday.
The Eagles (3-1), who had picked up just five first downs prior to their second-to-last offensive drive, moved the chains six times on that march and crossed midfield for the first time at the 4:57 mark of the fourth.
Jeremy Maclin made a one-handed 22-yard catch on 3rd-and-14 to put the ball at the 17-yard line. Foles then rolled right and hit Jordan Matthews, who came back to the ball for a gain of 11 yards.
LeSean McCoy dashed for five yards off left tackle on 2nd-and-goal to set the ball up at the 1-yard line, but Nick Foles tossed consecutive incompletions and Philadelphia turned the ball over on downs.
The Eagles tallied 90 of their 213 total yards on the drive.
Philadelphia forced a three-and-out to get the ball back, but Perrish Cox intercepted Foles on 4th-and-24 to seal the outcome for the 49ers (2-2) and give head coach Jim Harbaugh a victory over former Pac-10 foe Chip Kelly.
The Eagles had outscored their first three opponents 74-24 in the second half, while San Francisco had been trounced 52-3 after intermission, but the 49ers outscored Philly 13-0 over the final 30 minutes in this one.
San Francisco had the ball for 42:17 of the 60 minutes.
Frank Gore carried the ball 24 times for 119 yards and had a career-long 55- yard touchdown catch for the 49ers, who avoided a three-game losing streak.
Colin Kaepernick was 17-of-30 for 218 yards with two touchdowns and an interception in the triumph.
Foles completed just 21-of-43 passes for 195 yards with two interceptions and McCoy struggled to find holes behind Philadelphia's makeshift offensive line, running for just 17 yards on 10 carries.
The Eagles posted three non-offensive scores in the first half. Darren Sproles returned a punt 82 yards for a touchdown, Malcom Jenkins ran back an interception 53 yards for a score and Brad Smith recovered a blocked punt for a touchdown.
Philadelphia led 21-13 at the break, but Antoine Bethea forced a Zach Ertz fumble along the sideline on the Eagles' opening second-half series and Cox was able to establish possession prior to going out of bounds.
The 49ers capitalized on the miscue, with Stevie Johnson tip-toeing and keeping both feet inbounds inside the left pylon for a 12-yard score and get San Francisco within 21-20.
Philadelphia went three-and-out on its next touch and Phil Dawson nailed a 46- yard field goal to put the 49ers in front, 23-21, with 3:33 left in the third.
Dawson added a 31-yard field goal to extend the San Francisco margin to 26-21 with 6:35 remaining.
Earlier, the 49ers, who were the only team coming in with a touchdown on each of their first three opening drives, went three-and-out on their initial touch.
Connor Barwin shot right past left guard Alex Boone and Trent Cole came around the edge to sack Kaepernick on a 3rd-and-12 for a 13-yard loss to put the ball at the 2-yard line. Trey Burton then blocked the ensuing punt and Smith made the recovery in the end zone for a touchdown.
The 49ers answered with a 29-yard Dawson field goal to conclude a 14-play, 69- yard sequence.
Gore's touchdown reception came on a 2nd-and-17 on the first play of the second. Kaepernick scrambled to his left to avoid pressure and flicked a pass back across his body to a wide-open Gore, who stiff-armed Eagles safety Earl Wolff prior to crossing the goal line.
Philly was unable to get a first down, but Jenkins picked off Kaepernick and ran it back the other way three plays into San Francisco's next touch after Kaepernick tried to fit a pass to Brandon Lloyd running a slant.
Sproles scampered down the right sideline for his career-best 82-yard punt return for a score to stake the Eagles to a 21-10 cushion at the 8:49 mark of the second.
Dawson split the uprights from 51 yards out with 59 seconds left in the half.
The 49ers were 8-of-19 on third down, while the Eagles finished 5-of-13 ... San Francisco outgained Philadelphia 232-73 in the first half ... Maclin caught five passes for 68 yards ... 49ers right tackle Anthony Davis made his season debut, but left late in the first quarter with a left knee injury ... San Francisco tight end Vernon Davis departed with a back injury early in the third frame.