David Wright and the Mets have agreed to an eight-year, $138 million contract extension, ensuring that the franchise’s career hits leader will stay with the team as it continues to rebuild.

Wright, a six-time All-Star third baseman, must pass a physical to complete the deal, according to a person with knowledge of the talks, who spoke on condition of anonymity because the contract has not been announced. Once completed, it will be the largest guarantee in Mets’ history, surpassing Johan Santana’s six-year, $137.5 million contract.