The Rāmāyaṇa and the Mahābhārata are known as ‘itihāsa’ or epics. An itihāsa narrates a story that happened in the ancient days, and has come down to us by oral tradition. It may later be put in writing.
As per the definition given in some Sanskrit works, an itihāsa must contain topics dealing with all the four puruṣārthas viz., dharma (virtue), artha (wealth), kāma (desires of the flesh) and mokṣa (emancipation). This is generally done through the narration of incidents that took place in the olden days.
The words ‘itihāsa’ and ‘purāṇa’ have often been mentioned in the Vedic literature (vide Atharvaveda 15.6.4; Śatapatha Brāhmaṇa 126.96.36.199; Bṛhadāraṇyaka Upaniṣad 2.4.10). There, the difference between the two does not seem to be very clear.