The Texas Rangers agreed to a trade Wednesday night with the Philadelphia Phillies for left-handed ace Cole Hamels, sources told ESPN.

The Rangers also will get left-handed reliever Jake Diekman in the deal, in return for left-hander Matt Harrison and five prospects.

Top catching prospect Jorge Alfaro, outfielder Nick Williams and minor league right-handers Alec Asher, Jake Thompson and Jerad Eickhoff will be shipped to the Phillies, sources said. ESPN's Keith Law ranks Alfaro as his No. 49 prospect in the majors.

The Phillies had told several teams interested in acquiring Hamels that they'd like to get their "best" offers by Wednesday, sources previously told ESPN. The Phillies had continued to speak with a large number of teams about the 31-year-old lefty, including the Dodgers, Cubs, Giants, Astros, Diamondbacks, Yankees and Red Sox.

Hamels (6-7, 3.64 ERA) threw a season-high 129 pitches in Sunday's no-hitter over the Cubs at Wrigley Field. He would become the first pitcher in major league history traded during a season immediately after throwing a no-hitter.

Texas is seven games behind AL West-leading Houston and four games behind Minnesota for the AL's second wild-card spot.

Power Rangers The Rangers reportedly agreed to acquire Cole Hamels with an eye toward the future. They have a potentially formidable rotation locked up for several years.

Rangers Projected 2016 Rotation Signed Through* LHP Cole Hamels 2019 RHP Yu Darvish 2017 LHP Derek Holland 2018 LHP Martin Perez 2018 RHP Chi Chi Gonzalez 2021 * Including club options -- ESPN Stats & Information

"He's definitely a great pitcher,'' Rangers first baseman Mitch Moreland said after Texas beat the New York Yankees 5-2 Wednesday. "Obviously watched the no-hitter the other day, pretty impressive. He's got a long track record of great success. It will be huge for us.''

The 2008 World Series MVP was an integral part of the greatest run in franchise history, when the Phillies won five straight NL East titles from 2007 to '11, including two pennants and one World Series.

He was 114-90 with a 3.30 ERA in 10 seasons in Philadelphia. He went 7-4 with a 3.09 ERA in 13 postseason starts and also earned MVP honors in the 2008 NLCS.

"He's been here a long time, but that's baseball,'' Phillies catcher Carlos Ruiz said following an 8-2 loss at Toronto. "Definitely it's sad when you're around one of your teammates for a long time and then they have to go away.''

The rebuilding Phillies, an MLB-worst 38-64, traded All-Star closer Jonathan Papelbon to Washington on Tuesday. Both players made it clear they wanted to play for contenders.

Hamels has three years remaining on a $144 million, six-year contract, a deal that includes a club option for 2019. He's owed $22.5 million per year through 2018 with a club option for 2019 at $20 million or a $6 million buyout. His option becomes guaranteed at $24 million if he throws 400 innings or more in 2017 and 2018 combined, including at least 200 in 2018, and isn't on the disabled list at the end of 2018 with a left shoulder or elbow injury.

The Rangers effectively will wind up paying only about $40 million for the next three-plus seasons, a source told ESPN.com.

Alfaro, the key prospect heading to Philadelphia, is expected to miss the rest of the season because of an ankle injury he suffered in June. He was hitting .253 with five home runs for Double-A Frisco prior to the injury.

The Rangers acquired Thompson in a trade that sent Joakim Soria to the Tigers in July 2014. The Rangers' No. 4 prospect entering the season, according to Law, Thompson has struggled in the minors this season, with a 4.72 ERA in 87.2 innings at Double-A Frisco.

Asher was a combined 4-10 with a 4.43 ERA at Frisco and Triple-A Round Rock. Eickhoff was 9-4 with a 4.25 ERA for Round Rock.

Harrison returned earlier this month following spinal fusion surgery in June 2014. The 29-year-old lefty has a 50-35 career record with a 4.21 ERA.

Information from ESPN's Jayson Stark and Jim Bowden, ESPN Stats & Information and The Associated Press was used in this report.