Leotychidas II of Sparta
During the Greco-Persian Wars, King Leotychidas II of Sparta (reigned 491 to 476 BC) was appointed admiral in overall command of the Greek fleet in 479 BC, while he was king. He was in command at the time of the naval / land battle at Mykale.
This was the only time we know of that a Spartan king held this rank. Note that Leotychidas was appointed to this rank by the Spartan state; he did not have it by default simply because he was king.
The Eurypontid King Leotychidas II was the Spartan Navarch (ναυαρχος, admiral) for the year 479 BC during the Greco-Persian Wars. He was king at the time, having reigned since 491 BC. Sparta usually appointed a different admiral every year (though the rules were later bent somewhat due to the successes of Lysander) towards the end of the Peloponnesian War.
He was appointed in the aftermath of the Battle of Salamis, supposedly because the Spartans did not want him commanding the army, the position usually held by Spartan kings. This was because he had allegedly offended Apollo by bribing the Oracle at Delphi. Thus, instead of commanding the army at the Battle of Plataea in 479 BC, he led the combined Greek fleet at the Battle of Mycale. Leotychidas,
as commander-in-chief of the ‘Hellenic League’ fleet, ...fomented the
revolt of *Chios and *Samos, and decisively defeated the Persians in a
land and sea battle off Cape Mycale.
Source: Paul Cartledge, 'Leotychidas II'. In 'Oxford Classical Dictionary'
Leotychidas was exiled in 476 BC, this time accused of accepting a bribe. He died in exile, probably after 470 BC.
A note on the question and this answer
As @C Monsour has pointed out in his excellent answer, rulers in medieval times and earlier were often "functionally admirals" without having a specific title to that effect. Most simply wouldn't have felt the need to appoint themselves 'admiral' or 'commander of the navy'.
This is what makes the case of Leotychidas II different from the usual ancient practice, and thus worth mentioning; Sparta did have a title recognizable as 'admiral', 'commander of the navy' or 'commander of the fleet' (as opposed to land forces or other 'duties' of a ruler). Further, they later created the post of deputy navarch for Lysander as Spartan law did not allow someone to hold the position of navarch two years running. Even Athens, the main Greek naval power for most of the Classical period, did not have a 'navarch'; instead, they used the title 'strategos' (general) (i.e. the same as land forces).
That said, for ancient times, you may also want to consider Ramses III of Egypt and his defeat of the Sea Peoples at the Battle of the Delta (circa. 1175 BC) as he does appear to have personally commanded (but I'm not aware of any 'admiral' or equivalent title, and the surviving inscription accounts may well credit the pharaoh with more than his due).
Other source:
Alfred S. Bradford, 'Leonidas and the Kings of Sparta' (2011)