One New York team’s trash is another New York team’s treasure.

The NFL trade deadline makes strange bedfellows, and on Monday it brought the Giants and Jets together for an unprecedented deal. The Giants acquired defensive lineman Leonard Williams — a former Jets first-round pick — and sent a 2020 third-round draft pick and 2021 conditional fifth-round pick to the Jets as compensation.

It is the first Giants-Jets trade ever completed, an indication both teams are losing, desperate and willing to search for help anywhere. It also shows general managers Dave Gettleman and Joe Douglas do not subscribe to the theory about refraining from doing business with your next-door neighbor.

The fifth-round pick in 2021 becomes a fourth-rounder if Williams signs with the Giants prior to free agency — something the Giants very much intend on making happen. As a sweetener, the Jets are paying $4 million of the about $6 million Williams is owed for the remainder of this season.

Here is the deal with the deal: The Giants believe Leonard Williams is a young and ascending player, despite what many Jets loyalists think, and view him as a building block now and into the future.

Despite their crummy record, the Giants jumped in as buyers as the NFL trade deadline nears Tuesday. Of all their problems, defensive line did not feel like a front-burner issue after they took Dexter Lawrence with the No. 17 pick in the 2019 draft. Williams is only 25 and was the sixth selection in the 2015 draft, at the time regarded in some circles as the best player in that draft.

Williams, though, has not played to that level and he does not have a contract for the 2020 season. Why would the Giants send away two draft picks for a player they might be renting for half a season? That would make no sense, and the Giants are confident, after getting Williams in the building and acclimated to their organization, they can use that advantage and get him signed to a deal.

There is no debate Williams is highly durable, having missed only one game in four-plus years and starting 70 of 71 games. He was a solid player for the Jets, a run-stopper with 17 career sacks, but never broke out as an impact player and never lived up to his lofty draft status.

Williams has the third-most tackles for loss among interior lineman in the NFL since 2016 with 43, according to Pro Football Focus, behind only Aaron Donald (47) and Kawaan Short (44).

During his time with the Jets, Williams never had the luxury of playing alongside a legitimate edge rusher to take some of the blocking attention away from him. Williams does not have a sack this season, but his 14 quarterback pressures are twice as many as any Giants interior defensive lineman. The Giants see Williams as a disruptive force.

In the short term, Williams should immediately help the run defense. The Giants are allowing 122.4 yards a game on the ground. Williams since 2016 has 97 run stops, according to PFF and only Damon “Snacks’’ Harrison (140) and Akiem Hicks (103) have more in that span. Linval Joseph, like Harrison a former Giants player, also has 97 run stops.

Williams signed a four-year rookie deal worth $18.6 million and is working this season on the fifth-year option of $14.2 million. He will command fairly big money and the Giants are in sound financial shape in 2020, with Eli Manning’s contract coming off the books.

The Giants are 2-6 and the Jets are 1-6, both teams wallowing in losing. They face each other Nov. 10, a Jets home game at MetLife Stadium, and Williams will get a chance to line up against his former team and try to put a hit on Sam Darnold.

The Giants start B.J. Hill, Lawrence and Dalvin Tomlinson on their three-man defensive line. Hill is 24, Lawrence is 21 and Tomlinson is 25. The Giants did not acquire Williams to stand on the sideline. Hill has not been great in year No. 2 after a promising rookie season. Yet Hill and Tomlinson are not expensive and still so young they can exist in a rotation along with mainstays Williams and Lawrence.

“Each guy up-front has had an impact and played pretty good at times,’’ coach Pat Shurmur said Monday. “Yesterday was probably one of B.J. Hill’s better outings. Going forward, I think Dexter Lawrence is battling and playing hard, and Dalvin. Those are the three guys that come to mind right now that are very steady.’’

For more on the Giants, listen to the latest episode of the “Blue Rush” podcast: