Agni plays an important role in the Ramayana in the agnipariksha ("test by fire"), when Sita demonstrates her purity by entering into the fire. In the legend of the Maya Sita, the god Agni returns the true Sita to Rama in that moment.
In the Mahabharata, Agni has decided to burn the Khandava Forest, and asks for help from Arjuna and Krishna to keep the storm god, Indra, from putting out the fire before Agni has consumed the whole forest. Here's an amazing modern painting of that story by Parama Libralesso:
And here's a traditional depiction of Agni riding a ram (British Museum):