Financial terms were not disclosed, but Martinez said he would send some of the money to relatives in his native Venezuela, which has been plagued by food and medical shortages and a political crisis.
"It's not even for me, just for my family," Martinez said. "It's a tough situation there. You have a little incentive for sure."
Martinez led the Cardinals with a .305 batting average and 163 hits last season. He was also second on the team with 83 RBIs.
"Jose is going to get at-bats somewhere this year," general manager Mike Girsch said. "We just don't know how it's going to work out. And I'm sure he'll continue to hit."
Manager Mike Shildt said Martinez received "two hearty rounds of applause" from teammates when they were told about his deal.
"It was really an honor to be able to say that in the clubhouse," Shildt said. "He's an important part of what we're doing."
Martinez would have been eligible for arbitration after the season. He won't be eligible for free agency until after the 2022 season.
He played 887 games in the minors before finally reaching the big leagues but has hit .309 over parts of three seasons since arriving.
"He has had a unique career path and has been a huge part of our team the last couple of years," Girsch said. "We felt the right thing to do was to give him some certainty."
The Cardinals also announced that right-hander Miles Mikolas will start Opening Day at Milwaukee on March 28. Mikolas returned to the major leagues last year after three seasons in Japan, became a first-time All-Star and went 18-4.
"A year ago, saying Miles would be our Opening Day starter this year would have been a shock to everyone," Girsch said. "He pitched amazing last year."
The Associated Press contributed to this report.