With talks of a contract extension for Danilo Gallinari cooled, the Heat’s trade for Andre Iguodala appears to be going ahead as a two-team deal.

Miami has agreed to move Justise Winslow, Dion Waiters and James Johnson to Memphis for Iguodala, Solomon Hill and Jae Crowder, according to ESPN’s Adrian Wojnarowski.

The sides had been discussing an expanded swap that also would have sent Gallinari to Miami, ahead of Thursday’s 3 p.m. NBA trade deadline.

Gallinari, a former first-round pick of the Knicks who was traded in the Carmelo Anthony trade in 2011, can become a free agent this summer.

“If Miami and Oklahoma City could reach a deal on Gallinari, there’s still time to make this a three-team trade — but those talks are fully stalled,” Wojnarowski tweeted.

The Heat (34-16) is looking to preserve cap space for a max free-agent signing in 2021 and already has agreed to a two-year $30 million extension with Iguodala, although the second season of that deal includes a team option for cap flexibility.

Gallinari, 31, is averaging 19.1 points per game while shooting 41.3 percent from 3-point range in 43 games this season for Oklahoma City.

Iguodala, a three-time NBA champion with Golden State, has been sitting out all season and seeking a trade since the Warriors dealt him to Memphis to clear salary-cap room in July.