Mahabharata is one of the epics of ancient India(other is Ramayana) and was written by Vyas also known as Veda Vyas. But there is a story involved behind how it was written.
Once Vyas sat for his meditation and observed series of vague scenes. He understood those scenes are based on the lives of his own descendants, decided to compose as a poetry. So he asked Lord Brahma to suggest someone who could write the verses as he dictates. Lord Brahma shown Lord Ganesha as a right person to that task and Ganesha too agreed with a condition and the condition was, Vyas must not stop while dictating the verses. Vyas agreed with a counter condition that Ganesha should put words down only after understanding the complete meaning of the verse.
Once Vyas sat for his meditation and observed series of vague scenes. He understood those scenes are based on the lives of his own descendants, decided to compose as a poetry. So he asked Lord Brahma to suggest someone who could write the verses as he dictates. Lord Brahma shown Lord Ganesha as a right person to that task and Ganesha too agreed with a condition and the condition was, Vyas must not stop while dictating the verses. Vyas agreed with a counter condition that Ganesha should put words down only after understanding the complete meaning of the verse.
During the process of dictation, Vyas used to compose verse with complex vocabulary that includes several shades and layers of meaning. So that Ganesha could take a break for few seconds to understand and Vyas could utilize that time to compose few more verses over his mind. And its been said that, those complex verses have not been understood by scholars yet.
Hence Mahabharata was written by Veda Vyas with the help of Lord Ganesha.