On June 11, 1557, the long-reigning king of Portugal, John III, a grandson of Ferdinand and Isabella of Castile, the financiers of Christopher Columbus’ transatlantic crossing, died suddenly at the age of 55. John’s son and heir, also called John, had died three years earlier aged just 16, and as a result, the Portuguese throne passed on to John III’s eldest grandson, Dom Sebastiao. He became King Sebastian I of Portugal, at the age of just 3.

A 3-year-old king, of course, has somewhat limited powers of governance. So, for much of his childhood and the early years of his reign, Sebastian’s role was taken over by his mother, Princess Joanna of Austria, King John III’s daughter-in-law. A patient, intelligent, and astute leader, Joanna and her court acted as regent on behalf of Sebastian until he was old enough to rule on his own. In that time, she established a strong and successful period in Portugal’s history, which saw the country flourish both domestically and internationally with the growth of its colonies and trade posts in Africa, India, and the Far East.

But in 1578, the now 24-year-old King Sebastian risked all of his mother and his court’s hard work by embarking on a risky crusade in Northern Africa.

The position of the rightful Moroccan ruler, Sultan Abdallah Mohammed— a long-time ally of the Kingdom of Portugal, was being threatened by Abdallah’s Turkish uncle, Mulay Abdelmalek. The sultan fled to Portugal in the summer of 1577 to request the assistance of King Sebastian and, ignoring all the best counsel of his teams of advisors, Sebastian agreed to assist. The following year, he raised an army and headed across the Straits of Gibraltar to North Africa.

In Morocco, Sebastian and his forces rejoined Sultan Abdallah Mohammed and his army of more than 6,000 Moorish troops, and together they headed deep into the Moroccan desert to wage war. On August 4, 1578, the armies clashed with Mulay Abdelmalek’s Turkish forces outside the town of Alcacer Quibir. The battle, now known as the Battle of Three Kings, due to the trio of combined forces it involved, was short yet bloody, with both sides losing over 7,000 men. And in the melee, King Sebastian I vanished.

Although reports of what happened to Sebastian vary, he is said to have been last seen riding his horse fiercely into the fray but is presumed to have either been killed in the fighting or else captured, taken prisoner, and executed shortly afterward. Regardless of his fate, however, when news of the young king’s untimely death broke back in Portugal, the country was thrown into disarray.

With no son and heir to take his place, Sebastian’s throne fell to his great uncle, Henry—the 66-year-old brother of the former king, John III—who quickly found control over the grieving country difficult to maintain. Worsening the situation, Henry died barely two years after his unexpected ascent to the throne, and so in 1580, Portugal was thrown into a bitter succession crisis that eventually spiraled into an equally bitter conflict. The War of the Portuguese Succession, as it became known, went on to cripple the country for the next three years.

Against this backdrop, many Portuguese people struggled to come to terms with the death of young King Sebastian. Even when King Henry himself claimed to have received Sebastian’s body from the Moroccan kingdom and given his remains a full royal burial in Lisbon, many people refused to believe that the body was his and that their adventurous leader had indeed perished on foreign soil. The succession crisis only served to worsen the people’s grief and rumors soon began to emerge that Sebastian had fled the battlefield in Morocco, survived the war, or else had escaped captivity—and moreover that he would one day return home to Portugal to rule his flourishing kingdom once more.

Even as the decades went by and the country’s succession crisis was resolved, the legend of Portugal’s lost king endured. Countless imposters and pretenders to the throne claiming to be Sebastian came and went, and even as a new century dawned the belief that the King was still alive and would return to save Portugal persisted. The faith of Sebastian’s supporters became so strong that a cult of “Sebastianism” was founded, and proved so influential that when a new king, John IV, was crowned in 1640, he was made to agree that he would surrender the throne should Sebastian I ever return to Portugal, even though, by that time, the “young” King Sebastian would have been well into his 80s.

By the early 18th century, now more than a hundred years after Sebastian’s death, this bizarre cult of Sebastianism had become ever more mystical, with its followers eventually imagining that their (now long deceased) king would return as a Messiah, purely in a spiritual form, and would rise from the dead to return Portugal to its former glory. And despite the cult’s increasingly impossible expectations, its numbers nevertheless continued to grow.

Eventually, however, common sense prevailed. By the 1800s, the cultish Sebastianism movement had largely disappeared. One of history’s most peculiar episodes, it seemed, was finally over.