The new pact starts in 2015 and includes a fifth-year club option for $12.5 million and a $2 million buyout. If traded, Gardner would receive $1 million.
"It shows the level of confidence, belief and trust, and the type of player and person he is," Yankees general manager Brian Cashman said. "We're excited to know that he's going to be a part of this team going forward. We're a better team with Gardy on it, that's the bottom line. This is a good day for him, and we believe it makes the future for us better."
Gardner has a $5.6 million, one-year contract for this season. He would have been eligible for free agency after the 2014 season.
"Free agency is something that, it kind of intrigued me, but it also kind of scared me," Gardner said. "I've never been anywhere else. I love it here. I love putting on the pinstripes everyday."
Cashman said talks about the contract started at the winter meetings in December.
The Yankees are moving Gardner to left field this year after the signing of free agent center fielder Jacoby Ellsbury to a $153 million, seven-year contract in December.
Gardner did have questions in his mind about his Yankees' future after the Ellsbury signing.
"When they signed Jacoby, your name gets thrown out in the trade rumors and all that," Gardner said. "It's kind of annoying, really. I didn't want to get traded. I don't want to go anywhere else, and I let them know that."
The 30-year-old Gardner hit .273 last year with eight home runs, 52 RBIs and 24 stolen bases.
"I like what he brings," Cashman said. "The speed dynamic, the defense, and I think the offense is there as well."
Also, the Yankees agreed to a minor league contract with injured closer Andrew Bailey, who was with Boston last year and is coming back from right shoulder surgery last July.
Cashman said the right-hander might be able to join the team in August or September.
"When he is healthy, he's an exceptional reliever," Cashman said. "He's coming off of a shoulder surgery, so we're taking a flier. A low risk. If we can get a reward out of it, great. If not, it's one of those nothing ventured, nothing gained."
NOTES: Yankees manager Joe Girardi attended a meeting with MLB officials Joe Torre and Tony La Russa Saturday on topics including instant replay. Girardi said the Yankees' first instant replay test game will be March 6 against Philadelphia in Clearwater. "It opens up us to more to have to answer for, but I think it gives our game the opportunity to have more things decided on the field, which I think is a good thing," Girardi said. The Yankees plan to work on replay situations throughout spring training even if it's not a test game. "We'll probably practice with walkie talkies," Girardi said. ... New York OF Alfonso Soriano missed his fourth day due to the flu, but could do a light workout Monday.