Determining the longest-reigning ruler in history depends on how you define "ruler" and "reign." If we consider monarchs who held the throne for the longest time, then the answer is King Sobhuza II of Swaziland, who reigned for a remarkable 82 years and 254 days from 1921 to 1982.
However, if we consider other forms of leadership, such as dictators or presidents, then the title of longest ruler might belong to Queen Elizabeth II of the United Kingdom, who reigned for 70 years and 214 days from 1952 to 2022.
It's important to note that these are just two examples, and there are many other potential candidates for the title of longest ruler in history depending on the criteria used.