In this May 24, 2019, file photo. Boston Red Sox second baseman Dustin Pedroia takes off for first base a rehab start for the Portland Sea Dogs at Hadlock Field. Credit: Troy R. Bennett / BDN

BOSTON — Boston Red Sox second baseman Dustin Pedroia, who was the AL Rookie of the Year in 2007 and the MVP in his second season but played in a total of nine games in the last three years because of a knee injury, retired on Monday.

A four-time All-Star who was the longest-tenured player on the Red Sox roster, Pedroia played in two World Series over 17 seasons and collected a third ring in 2018, when he was injured. In his career, he batted .299 with 140 homers and 725 RBIs.

“Dustin came to represent the kind of grit, passion, and competitive drive that resonates with baseball fans everywhere and especially with Red Sox fans,” Red Sox owner John Henry said. “We are forever grateful to him for what he brought to our club and to our region as an important role model showing all of us how much one can accomplish with determination and hard work.”

Pedroia, 37, is the only player ever to earn Rookie of the Year, Gold Glove and MVP awards along with a World Series championship in his first two full seasons. Only nine other players have accomplished those feats in their entire career.

But his career effectively ended early in the 2017 season when Baltimore’s Manny Machado slid into second base, spikes up, and connected with Pedroia’s left leg. Pedroia played in 105 games that year but had surgery afterward; he admitted to rushing back in 2018, when he lasted only three games before going back on the injured list.

“He’s the heart and soul of this team,” infielder Brock Holt said before the World Series, after the Red Sox won a franchise-record 108 regular-season games en route to the title. “He’s been here the longest. He’s won two World Series. So to have him here — it’s always better with him here than when he’s gone.”

In 2019, Pedroia played just six games. He continued to speak of a comeback before having what the Red Sox said was a “significant setback” in the offseason. He did not play at all in the pandemic-shortened 2020 season.

“It sucks,” Machado said after the 2019 setback. “Obviously, he could go down as one of the greatest Red Sox to play this game.”

Pedroia was a 2004 Red Sox draft pick out of Arizona State and spent three seasons in the minors, including part of the 2005 season with Boston’s Double-A affiliate, the Portland Sea Dogs.

Pedroia played 66 games for the Sea Dogs, batting .324 with eight home runs, 40 RBIs, 19 doubles and two triples.

He played six games with the Sea Dogs during a rehab stint in 2019.

Notes: Pedroia has one season remaining in a $110 million, eight-year contract. Of his $12 million salary for 2021, $2.5 million is deferred without interest and payable on July 15, 2028. His contract called for deferred payments for previous salaries of $2 million each on July 15 this year and in 2022, 2023 and 2024, and $2.5 million each in 2025, 2026 and 2027.