Outfielder J.D. Martinez, who hit more home runs last season than all but Giancarlo Stanton and Aaron Judge, on Monday agreed with the Boston Red Sox on the terms of a five-year contract worth roughly $110 million, according to sources.

The deal, which includes an opt-out clause for Martinez, is pending a physical.

Martinez was the best power hitter on the market. The Red Sox, last in the American League in home runs in 2017 (following the retirement of David Ortiz), sought power and had an opening at designated hitter. Still, negotiations were slow, reflecting the overall tenor of baseball’s winter market. Near the end, as position players reported to camps, Martinez’s agent, Scott Boras, was reported to be receiving interest from the Red Sox and Arizona Diamondbacks.

Though a regular outfielder over seven seasons in Houston, Detroit and Arizona, Martinez is not likely to take innings from Boston’s regular trio of outfielders – Mookie Betts, Jackie Bradley Jr. and Andrew Benintendi. Hanley Ramirez took most of Boston’s DH at-bats last season. While he hit 23 home runs (19 as DH), he also batted .242 and his OPS was .750, at or near career lows. The Red Sox also could trade Bradley to open right field for Martinez.

Released by the Houston Astros not four years ago, when he was 26 and had hit 24 home runs in nearly 900 big-league at-bats, Martinez reoriented his career over four seasons in Detroit and Arizona. Now 30, he entered free agency having hit 45 home runs (and batting .303) in 2017, and 128 in his past 1,929 at-bats, turning his finest season – only Mike Trout had a higher OPS in 2017 – into free-agency riches. Because of a foot injury sustained in spring training, Martinez missed the Tigers’ first 33 games, did not have an at-bat before May 12, and hit his first home run on May 13.

In mid-July, Martinez was traded from the moribund Tigers to the contending Diamondbacks, and his production helped propel the Diamondbacks to 93 wins. Over 62 games in Arizona, he had 29 home runs and 65 RBI. His OPS was 1.107. Four of those home runs came on one night in Los Angeles, when he became the first Diamondback and 18th player in history to homer four times in the same game. The home runs came in consecutive at-bats against four different pitchers. On Sept. 27, Martinez homered to tie Ralph Kiner’s record of 16 home runs in the season’s final month.

As he reworked his swing mechanics, approach at the plate and pregame preparation routine, Martinez credited the mentorship of former Tigers teammate Miguel Cabrera, once one of the most feared hitters in the league. In Arizona, he became a fan favorite hitting behind Paul Goldschmidt, forming one of the more fearsome one-two punches in the league until the Diamondbacks were swept in the division series by the Dodgers.

All of which seemed to position Martinez favorably in a market ahead of next year’s class, which is expected to bring the likes of Bryce Harper, Manny Machado and Josh Donaldson to the market.

Martinez’s return to Arizona seemed a long shot, as the Diamondbacks have kept their payroll under $100 million, and not so long ago seemed to regret their $206.5-million commitment to Zack Greinke. Greinke will make more than $30 million in each of the next four seasons. Goldschmidt is due a long-term extension as well. His contract runs through 2019.