From the Super Mario Wiki
A carrot has first appeared in volume 6 of Super Mario-Kun. Unlike most items, this carrot talks and plays a bigger role.
Carrots also make a brief appearance in Mario Kirby Meisaku Video. After Mario crashes his Kart during his pursuit of the mysterious thief W, who was trying to escape in his Plane, the Bulldog, Mario finds a garden full of Carrots, eats one, and transforms into Rabbit Mario.
Carrots also appear in Super Mario Advance (although not in the original Super Mario Bros. 2 and other remakes of said game) as platforms that would bounce up out of hills and help Mario and company reach higher lands. They only appeared in two levels, though.
A giant carrot known as the Giga Carrot appeared in Mario & Luigi: Bowser's Inside Story. It is a very old carrot that has been under the care of the Wiggler Family for generations. In the game, a member of the Wiggler Family forced Bowser to eat this carrot after he plucked it from the ground within a minute.