As per the Hindu tradition, Sage Vyasa narrated the Mahabharata and Ganesha wrote it down. The longest epic in the world was not the job for an ordinary scribe and therefore Sage Vyasa requested Ganesh to become his scribe. Ganesha put one condition that Vyasa should recite the Mahabharat non-stop. Vyasa agreed. But the wise sage put one condition before Ganesha that he should write only after understanding the lines that he dictated. Ganesh agreed to this condition.
It is said that Ganesha sometimes took time to understand some of the complex lines narrated by Sage Vyasa. The Sage used this pause to compose the next lines.
Another legend associated with Ganesh writing Mahabharat is that of the broken tusk of Ganesha. After some days of writing of Mahabharat the stylus used by Ganesh broke and as he could not stop writing he broke off one of his tusks and started writing with it. This symbolically explains that any amount of sacrifice is not too much to gain knowledge.