DeMarco Murray got the money he wanted from his former team’s biggest rival.

The All-Pro running back agreed Thursday to a five-year contract with the Philadelphia Eagles. Murray’s deal was valued at $42 million, with $21 million guaranteed, according to a person familiar with the deal who spoke on condition of anonymity because terms weren’t disclosed.

Wearing a gray suit, white shirt and black tie, Murray arrived at team headquarters with his fiancee, Heidi Mueller, on Thursday afternoon.

Less than two hours later, the Eagles confirmed they had reached agreement on a three-year contract with former San Diego running back Ryan Mathews.

The tandem joins Darren Sproles and Chris Polk in a crowded backfield.

Murray helped the Cowboys win the NFC East title last season while rushing for a franchise-record 1,845 yards. He broke the Dallas record held by NFL career rushing leader Emmitt Smith and also set a league mark with eight straight 100-yard games to start the season.

“We have great appreciation for his skills, and if there was no salary cap in place, DeMarco would be a Cowboy,” Cowboys owner Jerry Jones said in a statement. “This came down to an allocation of dollars within the management of the salary cap.”

Cowboys quarterback Tony Romo was asked about Murray at the Texas Rangers’ camp.

“I saw where he ended up signing and it was a tough decision,” Romo said. “It was tough on him over the last 48 hours. Anytime you have a close friend that moves teams, it’s never easy, especially when he’s going in the division. It’s part of playing in the National Football League. Our team, we love him and he’s been great for us. He’s meant a lot.”

Cowboys star receiver Dez Bryant tweeted: “@DeMarcoMurray I wish you would have stayed but I understand your decision… Congrats bro you deserve it -”

The Eagles swapped quarterbacks with St. Louis on Tuesday, sending Nick Foles to the Rams for Sam Bradford. They also let Pro Bowl wide receiver Jeremy Maclin sign a free-agent deal with Kansas City.

The Eagles appeared to replace McCoy with Frank Gore, but he backed out of a deal and signed with Indianapolis. Mathews agreed to his deal Wednesday and came in for a physical on Thursday.

Murray played with Bradford at Oklahoma. Bradford told reporters at his introductory news conference that he lobbied his former teammate to join him in Philly.

“I called him. I’ve texted him. I’ve done everything,” Bradford said. “We’ve been in communication and I think if we could somehow land DeMarco, it would be a great pickup.

“Not only is he a great player, but he’s a great person. He’s a really great friend of mine, too. I really think that he could help this ballclub.”

The 27-year-old Murray turned down a four-year, $16 million offer from the Cowboys last fall and went on to become the AP Offensive Player of the Year. He played 16 games for the first time in 2014 after missing games with injuries in each of his first three years.

Murray played the final four games last season, including the playoffs, after breaking his left hand in a win at Philadelphia. He tied Seattle’s Marshawn Lynch for the NFL lead with 13 touchdowns rushing. Murray has been to the Pro Bowl the last two seasons. He had 1,121 yards rushing and nine TDs in 14 games in 2013.

Matthews twice rushed for 1,000 yards in five seasons in San Diego. He missed 10 games due to injuries last year and has played 16 games only once in 2013.

Since taking control of personnel moves away from former general manager Howie Roseman, Kelly has played fantasy football with the Eagles, making several bold moves to reshape the roster to try to add players to fit his scheme and desired culture in the locker room. The Eagles have finished 10-6 in each of Kelly’s first two NFL seasons, but missed the playoffs last season after a 9-3 start.