Eagles wide receiver Riley Cooper, who stood to become a free agent in less than two weeks, won’t be leaving the nest.

Cooper, who broke out for 835 yards and eight touchdowns this past season, will sign a four-year deal with the Eagles on Thursday, according to a league source familiar with the contract talks.

The Philadelphia Inquirer and Pro Football Talk reported earlier Wednesday that the Eagles and Cooper, 25, were nearing an agreement. Cooper’s prior contract was set to expire on March 8, the start of free agency.

Cooper, entering his fifth season, overcame a training camp nightmare after his racial slur that was caught on camera went viral and turned him into a national villain and polarizing figure in the locker room.

The Eagles welcomed him back after he left the team briefly to undergo counseling and then Cooper had the best season of his career.

He ranked second on the team in receiving yards, second in receiving touchdowns and averaged nearly 18 yards per reception for an offense that helped propel the Eagles from worst to first in the NFC East and get back to the playoffs for the first time since the 2010 season.

Cooper, a 2010 fifth-round pick out of Florida, is the second member of an offense that set records for total points and yards to sign a long-term deal this week as general manager Howie Roseman is busy ensuring that his record-setting offense remains intact for coach Chip Kelly’s second season.

Left tackle Jason Peters signed a five-year extension (see story)and center Jason Kelce and wide receiver Jeremy Maclin are also in line for extensions. Maclin, according to a league source, is making progress toward a new deal and both sides are talking (see story).

Roseman met with representatives for Cooper earlier this week at the NFL Scouting Combine in Indianapolis, where talks toward a new deal heated up.

For the first three years of his career, Cooper produced modestly as a backup and played a more significant role on special teams. He stepped into a starting spot after Maclin tore his anterior cruciate ligament early in training camp and capitalized on his opportunity, even after his viral racial slur threatened his standing with teammates and ownership.

Two of Cooper’s three 100-yard receiving games came this season, including a personal-best 139 yards and three touchdowns against the Raiders on Nov. 3 at O.Co Colliseum.

Cooper came on after Nick Foles replaced Mike Vick as the starting quarterback. With just eight receptions in his first five games, Cooper caught 39 passes in his next 11 and had five games of at least 74 yards.