It was the deal that had to happen, a match made in heaven for two organizations trending in much different directions.

At about 10:59 p.m. Central time Thursday, the Detroit Tigers traded ace Justin Verlander to the Houston Astros for three prospects.

The two teams had talked extensively about Verlander leading up to the July 31 trade deadline and intermittently over the next month, but finally came to an agreement with less than a half-hour to go before the waiver trade deadline. It was then up to Verlander to waive his full no-trade clause, which he did shortly before the 10:59 p.m. deadline.

Detroit received righthander Franklin Perez, outfielder Daz Cameron and catcher Jake Rogers. The Tigers are also reported to be sending at least $10 million to the Astros, according to Yahoo Sports, with Verlander signed through 2019 with a vesting option in 2020. Verlander, 34, makes $28 million in each of the next two seasons.

The departure of Verlander means these Tigers are nearly unrecognizable. They are now a team stripped of a franchise player and are fully embracing rebuild mode, which was signaled earlier Thursday when they traded left fielder Justin Upton to the Los Angeles Angels.

Verlander, 34, is arguably the best Tigers righthander of all time. In 13 seasons, he was 183-144 with a 3.49 ERA and six All-Star appearances. He was the AL MVP and Cy Young Award winner in 2011. Last season, he finished second for the Cy Young.

Houston receives a proven postseason pitcher — Verlander is 7-5 with a 3.39 ERA in 16 playoff starts — who should sit atop its rotation. The Astros are all but assured of the AL West title and, with a top-ranked farm system, could afford to part with prospects.

Angels bolster lineup

The Angels acquired a pair of veteran stars to bolster their playoff push, acquiring four-time All-Star outfielder Justin Upton from Detroit and second baseman Brandon Phillips from Atlanta.

The Angels (69-65) are in playoff contention despite one of the AL’s least potent lineups. They rank 12th in the AL in runs scored. Their trades gave them upgrades in left field and second base.

For Upton, Los Angeles gave up pitching prospect Grayson Long and cash or a player to be named. The Angels also let Cameron Maybin leave on a waiver claim by the Astros, clearing the way for Upton to take over in left.

Upton, 30, was an All-Star this season with the Tigers, batting .279 with 28 homers and 94 RBI.

Phillips, a three-time All-Star and four-time Gold Glove winner, was traded a day after he got his 2,000th career hit. He was in his first season with Atlanta after 11 years with Cincinnati. The Braves acquired minor league catcher Tony Sanchez.

Phillips had a partial no-trade clause that included the Angels, but he approved the trade just before the deadline for a player to be eligible this postseason.