He started off as an egg, which was imported from a southern island to be an extra ingredient for Mr. Hoggle's Hot Dogs. However, that plan backfired, since the Yoshi was still alive in the egg, and began jumping around. Unable to catch it himself, Mr. Hoggle asked Mario and his partners to get it for him. They succeeded, but eventually Mr. Hoggle decided that he didn't want the egg anymore, since he figured that no one would want to eat anything that "jumps around". Yoshi, while inside the egg, started to accompany Mario and his party, until he eventually hatched during their battle against the Iron Adonis Twins. After the Yoshi hatched from the egg, he thanked Mario and company for saving him from Mr. Hoggle, and agreed to fight alongside them for the rest of the game.
Outside of battle, Mario can ride Yoshi to move faster, or to get across narrow gaps that Mario cannot jump across on his own, much like Parakarry from the first Paper Mario. Yoshi's default abilities in battle are Ground Pound, which takes up one of an enemy's HP at a time (much like Lady Bow in the first one), and Gulp, where he'll use his tongue to get an enemy into his mouth, and then spit it back out, and hit another enemy. When powered up, Yoshi gains the Mini-Egg attack, which is capable of lowering enemies' attack power, as well as Stampede, where he summons an army of Yoshis to attack.