Phra Aphai Mani and his brother, Sisuwan, are Thai princes. Their father sent them away to study with the hope that they would gain knowledge to help them rule the country. Sisuwan learned to sword fight and Phra Aphai Mani learned to play a magical flute that could put people to sleep or kill them. When they returned home, their father was angered by what they had learned and drove them away.
One day while Aphai's companions were lulled to sleep by the sound of his pipe, a female ogress named Nang Phisua Samut, came and took Aphai away to her cave. She disguised herself as a beautiful maiden and Aphai fell in love with her. They lived together until she bore a son, Sinsamut. When Aphai found out that his wife was really an ogress, he fled with his son. He was assisted by a family of mermaids, a father, mother, and daughter. The father and mother were caught and eaten by the ogress. The mermaid daughter took Aphai and Sinsamut to Kokaew Phitsadan (Wonder Island) where a hermit saved them from the ogress. Aphai married the mermaid daughter and they had a son, named Sutsakhon.
One day, a ship, carrying King Silarat and Princess Suwwanmali of Phleuk, passed Wonder Island. The princess was engaged to marry Prince Usaren of Lanka. Aphai and Sinsamut asked to join the ship, but the ogress saw them and became very angry. Nang Phisua Samut attacked them and killed King Silarat. Aphai escaped to the shore, where he played his magic flute and killed the ogress. Afterwards, he met Prince Usaren, who was looking for his fiancée.
Meanwhile, Sinsamut swam with the princess to an island and met Sisuwan and his daughter, Arun Rasami. Together, they went in search of Phra Aphai. When they found Phra Aphai and Usaren, Princess Suwwanmali refused to leave with Usaren. The two parties fought and Prince Usaren fled to his homeland of Lanka.
Phra Aphai continued on to Phleuk where the queen asked him to rule the country. Angry at Phra Aphai for daring to give her up to Usaren, Princess Suwwanmali fled to become a nun. But later with the trick of a maid, Nang Wali, Suwanmali abandoned the nunhood to marry Phra Aphai. She bore him twin daughters named Soisuwan and Chantasuda.
Years later, Usaren and his father returned to attack Phleuk. The father was killed and Usaren died heart-broken. The throne of Lanka fell to his sister, Nang Laweng. The very beautiful Laweng decided to take revenge. She declared to all the princes in neighboring that whoever could kill King Aphai would have her and her kingdom. Nine armies moved to surround Phleuk. Aphai followed Laweng and eventually won her love, but the war continued until a hermit came and helped to stop the war between them.