The Mets retained one of the most electrifying players in franchise history, agreeing to terms on a four-year, $110-million contract with slugging leftfielder Yoenis Cespedes, sources confirmed Tuesday.

When Cespedes passes a physical and the deal becomes official, as is expected this week, his annual average salary of $27.5 million will establish a record for outfielders. That average annual value will rank second all-time among position players only to the Tigers’ Miguel Cabrera.

And when it comes to average annual value, it is the most lucrative contract ever awarded by the Mets, who essentially paid that premium to avoid giving Cespedes a fifth guaranteed season. Another concession included giving the 31-year-old Cespedes a full no-trade clause, according to a source.

The source also confirmed that the contract is backloaded, with Cespedes slated to make $22.5 million in 2017, $29 million the following two seasons and $29.5 million in his final year. That salary structure will prove particularly helpful as the Mets continue to fill out their remaining holes this offseason.

With Cespedes returning and lined up to play leftfield, a source said the Mets will look to trade from their glut of lefthanded-hitting corner outfielders.

Jay Bruce remains likely to be traded, though a source said Tuesday that Curtis Granderson is also a possibility to be moved. Each has only one year left on his current deal, making them attractive targets. Bruce is owed $13 million in 2017, while Granderson’s salary is $15 million. The contracts are relative bargains, and both already have generated trade interest.

advertisement | advertise on newsday

Michael Conforto, another lefty-hitting corner outfielder, also has attracted interest in the trade market. But a source said that the 23-year-old, who is coming off a down season, is likely to stay put. He is not a free agent until 2022 and could be used as a centerfielder, leaving Bruce or Granderson more likely to be moved.

The Mets also still want help in the bullpen, which could come through a trade. With closer Jeurys Familia almost certainly facing a suspension for his arrest on domestic violence charges, the Mets’ need for another back-end reliever has taken on more urgency.

The Mets also need a lefty specialist. They have been open to retaining free agent Jerry Blevins for that role, though it’s possible that he lands a more lucrative deal elsewhere.

While some work remains for general manager Sandy Alderson, the Mets accomplished their most important goal of the offseason. They have kept Cespedes in Flushing, where his raw power, flair for the game and penchant for thriving in big moments turned him into a fan favorite since his arrival from the Tigers in a deadline-day trade in 2015. He has been a force in the lineup ever since.

Cespedes helped the Mets win the NL East en route to the pennant and a World Series appearance. In 2016, Cespedes hit .280 with 31 homers and 86 RBIs in 132 games, helping the Mets overcome injuries to reach the wild-card game.

Mets videos

The Mets thought they would be priced out of a Cespedes reunion last winter, when he was expected to land a megadeal on the open market. But when it didn’t come to fruition, Cespedes signed a three-year, $75-million contract with an opt-out after the first season. After a big year, Cespedes exercised that opt-out, again making him a free agent. But he made little secret of his affinity for the Mets.

And this year, the talks took on a different tenor, with the Mets acting more aggressively in the early stages to strike a deal. While last year’s talks dragged on until late January, a source said this agreement was agreed upon Tuesday morning, six days before the winter meetings will start.

The contract represents a critical step for both sides. Though it came a year later, Cespedes comes away with the long-term commitment he had long desired. The Mets are his fourth team in his five-year major-league career. Counting his salary last season, the Mets have committed five years and $137.6 million to Cespedes.

The pitching-rich Mets kept the most important piece of their lineup intact, further signaling their intent to challenge the world champion Cubs for the pennant.