Chip Kelly and Rex Ryan shook up the NFL just a week before free agency Tuesday, with Kelly agreeing to send former league rushing champion LeSean McCoy to the Bills for linebacker Kiko Alonso.

A league source confirmed the surprising deal, which won’t be official until the NFL’s new league year and free agency start next Tuesday. The trade is straight up, with no draft picks included.

Not only will the swap reunite Alonso with his college coach at Oregon, but Kelly also continued his recent money-clearing binge under the salary cap.

Just in the past two weeks, the Eagles have cleared $30.275 million under the cap by trading McCoy and cutting tight end James Casey, cornerback Carey Williams, offensive lineman Todd Herremans and linebacker Trent Cole. The moves so far have left Kelly $48.6 million in cap room for free agency.

The trade definitely had the look of a salary dump by Philadelphia, with McCoy scheduled to make $24.25 million over the next three seasons while Alonso — still working on his rookie contract — is set to earn just $1.7 million over the next two years.

Kelly, who showed last year by cutting DeSean Jackson that he isn’t afraid to get rid of star players, is gambling McCoy’s best days are behind him even at the still-tender age (for a running back) of 26.

McCoy, whose nickname is “Shady,” was an instant hit in Kelly’s no-huddle offense when Kelly took over in 2013, rushing for an NFL-best 1,607 yards and nine touchdowns and leading the league with 2,146 yards from scrimmage.

McCoy tailed off slightly as a ball carrier last year, gaining 1,319 yards and five TDs on the ground, but really disappeared in the passing game. He caught just 28 passes for 155 yards in 2014, compared to 52 receptions for 539 yards in Kelly’s first season.

It didn’t take long for McCoy to become the featured back in Buffalo. Just moments after the trade was initially reported, former Bills running back C.J. Spiller told the NFL Network the team already had called to tell him he is no longer in its plans and he is free to sign elsewhere in free agency.

Ryan also cleared a logjam at linebacker by parting company with Alonso while getting rid of a player who — although extremely talented — is dogged by health concerns.

Alonso missed all of last season with a torn anterior cruciate ligament suffered in a summer workout, and that injury followed surgery to repair a torn labrum in his hip in May 2014. Alonso also missed the entire 2010 season at Oregon due to another torn ACL.

When healthy, though, Alonso is a productive and promising young player. He quickly became a fan favorite in Buffalo as a rookie in 2013, recording 159 tackles and four interceptions while challenging eventual winner Sheldon Richardson of the Jets for NFL Defensive Rookie of the Year honors.

Alonso told reporters last week he expects to be fully healthy for the start of training camp.