The Buddha left no written text and appointed no successor, saying that the teaching and the discipline would be the teacher after him. The tradition holds that in the rains retreat following his death five hundred arahants gathered at Rajagaha under the presidency of Mahakassapa to establish what he had actually said, before memories diverged and before anyone could claim whatever suited them.
The account describes a division of labour that still shows in the texts. Upali recited the monastic rule, because he was held to be the foremost in discipline, and Ananda, who had been the Buddha's attendant for decades and had heard almost everything, recited the discourses. This is why the discourses open with the formula thus have I heard: they are presented as Ananda's testimony, delivered at this council, rather than as anonymous scripture.
Two details in the traditional account are more interesting than a smooth story would allow. Ananda is said to have attained arahantship only on the eve of the council, having been excluded until he did, and to have been rebuked afterwards over several minor matters. And the elder Purana, arriving later with his own company, declined to accept the recension, saying he would continue to remember the teaching as he had heard it from the Buddha himself. A council convened to fix the tradition recorded, in its own account, a monk who would not be bound by it.