In his youth Valmiki was infamous as a highway robber. Young and strong, he pounced upon travellers going by desolate roads and snatched away their money and valuables. He knew this was improper, but he believed it was the sole way he could make his livelihood. Moreover, his father, mother and wife were at home, depending upon him.
Into his early days of life, his youth, one day Valmiki caught hold of a traveller who possessed nothing. Infuriated, he asked him how he could wander around like that. "I am the sage Narada," replied the traveller. "I travel freely even between heaven and earth. I am one of the 'immortals'." Narada enquired about this man whether his family would share in his sins. Valmiki replied they would, but was not sounding too convinced about it. Narada asked him to return home and find out. So the 'robber' tied Narada securely and went back to his family. Valmiki's father, mother and even his wife outright declined to share his sins. They were appalled that all these years they were being sustained with evil. They stigmatized Valmiki and renounced him. The incident acted as an eye-opener to the 'robber'. Going back to the tree where Narada was tied, he told the sage what had occurred. He solicited clemency and asked Narada how he may atone for his wrongdoings. Narada taught the young man to worship and told him to go into the forest. Valmiki went into deep into seclusion and began practicing meditation and prayer. He kept this up for several years, surviving at first on fruits and roots. Eventually he became totally absorbed in meditation and forgot himself, losing consciousness of his physical body. As a result, ants gathered around him, creating anthills around him, heaped up high, so that he looked like a mountain of ants.
After numerous years, the time which was significant for Valmiki during his early life, a divine voice answered to him: "Arise, O Sage, your guilt has been erased; you have had a new birth, and you now have a new name: Valmiki -- meaning, he that was born in an ant-hill."
The newly evolved Valmiki founded his own hermitage and soon earned the respect of visionaries and commoners alike. Once again Narada visited Valmiki's hermitage. After the usual welcome Valmiki asked him as to who among the heroes of this world was the loftiest in virtue and wisdom. To this question, Narada answered that Rama was the hero who born in the solar dynasty, was at present ruling in Ayodhya. Sage Narada then briefly narrated to Valmiki the story of Rama. So affected was Valmiki when he heard Rama's story, that even long after Narada had left, his mind was engrossed in it. He was pondering on it as he went to the river Tamasa for his morning ablution. While he was walking along the riverbank, he saw in the nearby tree two doves sporting and singing in their joyfulness of life. Accidentally the male bird fell down, struck by a hunter's arrow. The female bird, seeing her lover rolling on the ground, deplored wretchedly.
By now, Valmiki was thoroughly transformed from that highway robber in his early life, into a tranquil and enlightened sage. Observing the sorrowful incident, Valmiki burst out in a curse. He cried, "Oh, hunter! As you have killed one of the love intoxicated birds, you will wander homeless all your long years." But in a moment the sage recovered himself and was wondering why he had turned so irritated and got so infuriated as to inflict a curse on the hunter. Recalling his words, the sage marveled at their rhythm. He distinguished that his pity had taken the shape of an exquisite verse. While he was engrossed in meditation that day, Lord Brahma appeared and told him that whatever had happened was to inspire him to write the story of Rama. "Sorrow has given birth to verse," said Brahma, "and in this metre and rhythm the story should be told. I shall give you the vision to see all that has happened, even how the characters thought and looked." Brahma then blessed Valmiki and disappeared.
This is how Valmiki wrote the Ramayana, entirely changed from a goon in his early life, into a scholarly sage, forever to be remembered in India. He not only penned it during the time of Rama, but also played a significant role in it towards the end. When Sita, Rama's wife, is deported because a citizen had suspected that she might have been tarnished during her abduction, she is given shelter by Valmiki.