On his journey home to the Shire, Bilbo gave the Elvenking a gift in recompense for the food and wine he had stolen during the outward journey. Seeing this as a noble act, Thranduil named him Bilbo the Magnificent, and granted him the title of Elf-friend.
It was traditional in the Brandybuck family for each Master of Buckland to have their own epithet, and Merry became known as 'Meriadoc the Magnificent'. It's never revealed quite when or how he acquired this title, but it seems sure that his exploits during the rallying of the Shire and the defeat of Sharkey must have played an important part.