He was the son of the brahmin Adityasharma. Once Adityasharma went to the forest and invoked an apsara named Sulochana. Their son was Gunasharma and with that Adityasharma became a deva. Gunasharma excelled in everything. Once Indra visited the place and Adityasharma, deep in thought, didn’t get up. Indra thought he was being disrespectful and cursed that he would be reborn as a human. He begged for mercy and Indra said that his curse would not be repealed but Adityasharma’s son could be reborn in his place. Thus Gunasharma was born. Ujjaini was then ruled by Mahasena. His wife was the beautiful Ashokavati. Gunasharma gradually became a good friend of Mahasena. The king and queen, who learned that Gunasharma was proficient in many things, made him dance for them once. From then on, he stayed at the palace and taught Ashokavati dance. Once an attendant tried to poison the king’s meal and Gunasharma caught him, saving the king’s life. Later, he rescued the king from where his enemies had imprisoned him, using his sorcery. The king gifted him a thousand villages.
Ashokavati once became infatuated with him but he rejected her. She was furious and turned the king against him, but he escaped. He then lived with a brahmin named Agnidatta and married his daughter Sundari. On Agnidatta’s advice, he prayed to Subramanya and acquired new skills. Using these, he defeated Mahasena and Ashokavati and sent them into exile as per Kathasaritasagara Suryaprabhalambaka Taranga 6.