The Yankees are about to unite the only two players to better 50 home runs last year.

They have an agreement in principle to acquire Giancarlo Stanton from the Marlins to put him in the same lineup and outfield with Aaron Judge. A source told The Post that Starlin Castro and two prospects, Jorge Guzman and Jose Devers, make up the return.

Marlins scouting and player development director Gary Denbo used to work for the Yankees, and knows Guzman and Devers well.

Neither team had announced a deal as of early Saturday morning, possibly because a physical review was still needed and that would not be a rubber stamp with Stanton, who has had injury problems throughout his career.

The Cardinals and Giants, who had presented the Marlins with frameworks of a deal for Stanton, bowed out of the race Friday, citing the fact Stanton had invoked his no-trade clause when it came to being dealt to St. Louis or San Francisco.

Enter the Yankees. Stanton listed the Yankees, his hometown Dodgers and the Astros as teams to which he would accept a trade, perhaps the Cubs as well.

But once the Cardinals and Giants – the teams with the greatest need for Stanton and, thus, what had been the strongest pursuit, was out of the way, the Yankees had a clearer rode to Stanton. He is owed $295 million over the next 10 years and Derek Jeter and Bruce Sherman bought a Miami franchise $400 million in debt. Do the math. The quickest, best way for them to begin to get toward long-term financial balance was to move as much of Stanton’s contract as possible.

The Yankees were not prioritizing an outfielder or righty power. But once the competition mainly fell away and the price also fell to where it was acceptable, the Yankees felt they could not ignore a star such as Stanton.

The key issue for the Yankees was that the Marlins take either salaried veterans and/or a portion of Stanton’s remaining contract so they can stick to their vow to stay under the $197 million luxury tax in 2018.

Miami is expected to eat $30 million of the money Stanton is owed, which would reduce his salary for luxury tax purposes in 2018 to $22 million. Castro, at $8.6 million toward the tax, would also defray a piece of it.

After all, the Yankees’ main offseason target is to acquire one, perhaps two starting pitchers while staying under the threshold and nothing has changed.

Well, actually so much as changed. Ten days ago, the Yankees were viewed as the favorites for Shohei Ohtani and not really in on Stanton. On Friday, Ohtani signed with the Angels and the Stanton to the Yankees deal became “virtually done” in the words of a source briefed on the matter.

Stanton led the majors in homers with 59 and was the NL MVP, while Judge was the runner-up for AL MVP. That duo plus Gary Sanchez would give the Yankees the most righty power it is history.

The Yankees likely would rotate Stanton and Judge plus Brett Gardner and Aaron Hicks in the outfield and DH slot. Stanton also would probably have a positive impact on Yankees ticket sales and TV ratings, which was another reason to push for him once the price dropped to a level with which the Yankees were comfortable.

Guzman, 21, was the Yankess’ No. 9 prospect, according to MLB Pipeline. He struck out 88 batters in 66 2/3 innings for short-season Staten Island last season. Devers was not ranked among their top 30 prospects.

Devers, 18, is a shortstop who played in the Gulf Coast League last season and is the cousin of Red Sox infielder Rafael Devers.