Three-time Stanley Cup winner Matt Cullen announced Wednesday that he is retiring after 21 seasons in the league.

The 42-year-old won his first Cup with Carolina in 2006 and then captured back-to-back titles with Pittsburgh in 2016 and ’17.

In an essay on NHL.com, Cullen wrote that his career almost came to a close before his last two titles.

Matt Cullen: his story, his words.https://t.co/rsL9o4yk1j pic.twitter.com/985mgUtqpk

“The phone didn’t ring on July 1, 2015, the annual start to NHL free agency,” he said. “I had just finished two great years in Nashville, but my future was still unclear. I still wanted to play even at 38 years old, but I was pretty sure that it was the end.”

Then he got a call from Penguins general manager Jim Rutherford.

“I just pinch myself and think about how close it was to not happening,” Cullen said. “Those were probably the best years of my whole career and life with the Penguins. Going through all that with the boys and Bridget and that group of players, the whole organization, everything was perfect. It was beyond anything I could have ever imagined.”

Cullen said that he has been “in a constant state of almost-retirement for the last few years” and that he knew this past season would be his last.

He spent three of his past four seasons in Pittsburgh, with the 2017-18 season back home in Minnesota.

“It was an emotional time, but I knew it was coming. It just felt right and I was really at peace with everything when it was over.

“I felt like it was only right to retire in Pittsburgh with everything that the organization had given me and done for me,” he said. “I’m so happy I came back and finished my last year in Pittsburgh. I wouldn’t trade that last year for anything.”

A second-round pick of Anaheim in 1996, Cullen played for the Ducks, Hurricanes, Panthers, Wild, Penguins, Panthers, Predators, Rangers and Senators.

He finishes with 266 goals and 465 assists.