Medieval kings and queens are often assumed to have been absolute, "divine right" monarchs. But this is not true--such monarchs instead are found only in the early modern period, the Ancient Régime (sixteenth through eighteenth centuries). Medieval monarchs were elected.
Elected? you say. You don't mean peasants had access to the ballot box? No, of course not. When the US was founded, only propertied men could vote, and women got the vote only after World War I, after many decades of effort by people like Susan B. Anthony, who didn't live to see it. The ability of southern blacks to vote was tenuous at best until the 1960s. So we shouldn't expect medieval voting rights to match the twenty-first century.
If one wanted to be a king in medieval Europe, one needed both to be part of a family considered royal and to be elected by a council of the powerful. In the Merovingian dynasty in early medieval France (fifth-eighth centuries), any male descended in the male line from Clovis, the first king, seemed to imagine he had the right to be king, regardless of details like illegitimacy or a plethora of brothers and cousins. This led to some extremely nasty family feuds. A would-be king needed at least some of the powerful to support, follow, and elect him.
The Carolingian dynasty, Charlemagne's family, started with his father Pippin, who deposed the last Merovingian king, had himself formally elected by his followers, and persuaded a bishop to anoint him. To add to this, he got the pope to bless him and his children as indubitably royal.
In the next centuries, a number of people challenged Carolingian rule, in all cases assembling nobles and bishops who were supposed to "represent" the will of the people, in order to be elected by them. (Our form of representative democracy derives from medieval forms.) Once kings, of course, they wanted to make the position hereditary, but it was hard to do so. And it was not automatic that the oldest son inherit.
In England, the duly elected Anglo-Saxon king was defeated in 1066 by William, duke of Normandy, now known as "the Conqueror." William was succeeded as king by his second, not first son, William II; the oldest son got Normandy. William II was succeeded by his younger brother Henry I. Henry, whose only legitimate son died by drowning (legitimacy had become more important than it had been during the early Middle Ages), was succeeded by his nephew Stephen (son of a daughter of William the Conqueror). Stephen in turn was succeeded by Henry II, whose mother was a daughter of Henry I. Henry II had five sons, but three of them died before he did, and the fourth, Richard "the Lionheart," died childless and was succeeded by his younger brother John.
(Interestingly, one of the sons of Henry II who predeceased him, Geoffrey, had had a son named Arthur. Young Arthur went to visit his Uncle Richard one day and was never seen again.)
For all of these successions, none of which match our vision of inheritance by oldest son, the great lords of England had to give their consent. We are now up to the early thirteenth century, and, for the first time, both French and English kings started asserting that their oldest son would inherit, even if not formally elected. But it took a long time to get there.
The castle in the image is Château Gailliard in Normandy, built by Richard the Lionheart.