Say a young and ambitious European farmer wanted to become a wealthy nobleman or even rule over a country. Could this be feasibly done? Did it ever happen?
In terms of becoming a monarch, no, I'm not aware of any time that happened in the middle ages. As for becoming wealthy, powerful and noble? It certainly seems to have been possible, to a limited extent, in any case in the areas I know best (which is France in the centuries around the turn of the millennium). Bear in mind though that this was a period of considerable social and political flux, which always allows for the relaxing for rules and chances for people to do things they otherwise wouldn't be able to.
One way in which peasants could advance was through the church. I've written about this before here. Here's the relevant bit:
Could a peasant become a member of the elite by joining the clergy?
Yes. But it was incredibly rare. It's also very difficult to determine how low-born these cases really were, because we usually know only that their enemies taunted them for being peasants, but medieval writers were incredibly snobby: to them being the 3rd son of the Count of Neverheardofitsville was practically the same as being a peasant, even if that wasn't the reality.
Hildebrand, the future Gregory VII, is the best example of this uncertainty: he is very often claimed to be of humble origins, the son of a Tuscan carpenter, but there are also suggestions that he was related to a previous pope, Gregory VI, and that he had family ties with some pretty important Roman monasteries. We do know that peasants could make it to the top. The one case in which it's universally accepted is that of Pope Silvester
IIIII, better known as Gerbert of Aurilliac (b. c.940), who rose from his early life as the son of a peasant from the mountains of the Auvergne in central France, to holding important ecclesiastical office in Spain, Germany and France, tutoring the Emperor's son, eventually being elected to the papacy (in 999) and generally being regarded as the most influential intellectual of the tenth century. But Gerbert was so unusual that future churchmen speculated that he could have been in league with the devil, his rise was so spectacular and unusual.
I get the sense that you're looking more for a secular route to power though. It's difficult to tell really, in particular because anyone who claims (or was accused) of lower origins might not really have been a peasant, but just a branch of some obscure local nobility. In the twelfth century, we do get some genealogical literature which gives humble origins to some powerful noble families (such as the counts of Anjou or the counts of Nevers-Auxerre), but how much of this is a literary trope is hard to determine - though if I had to guess I'd say they were 'humble' in the sense of emerging from the minor aristocracy, rather than from the peasantry.
The other possibility was for a peasant to become a knight, a group of people who were increasingly asserting their nobility throughout the eleventh century. The origins of knights are hotly contested, and tied up in a lot of other debates about medieval society, but there are some historians who believe that they originated in wealthy peasants basically starting to dominate and extort their neighbours, mafia-style. Others disagree, and see knights emerging from existing local, low-level aristocracies. It's a debate which doesn't look like being resolved anytime soon.
I guess the closes I can come to giving you a definite answer is that medieval people certainly thought that it could happen, even if we don't have specific examples. We can see this in the story of a serf from the lands of the Benedictine monastery of Fleury on the Loire in central France, written in the 1040s. He escaped from the monastic lands and went to live in Burgundy, where he rose up to become a respected local knight. The story comes from a miracle collection however, so we can't assume that this is an actual real example, but it is certainly something that they author thought his audience would believe could happen. The miracle happens later, when a patron of the abbey comes across the serf in Burgundy, and brings him to court to expose him. The serf tries to swear that he was always a knight, but St Benedict turns him into a black dog, thus proving his true wicked nature. He's transformed back into a man, and sent back to live his live of drudgery on the farms of the saint, and all is well with the world.
TL:DR; It wouldn't be possible for a peasant to become a king, but it was certainly thought possible for him to become a minor noble, even if such a thing was seen as a very bad thing by our aristocratic writers.
The Byzantine emperor Basil I (reigned 867-886) was the son of peasants, and originally came to court because his strength attracted the attention of a distant relative of Emperor Michael III, who hired him as a groom. He became involved in a planed coup, informed on and then murdered the plotters to gain imperial favour, and from there assassinated Michael and assumed the throne himself – thus founding the Macedonian dynasty, one of the most glorious in Byzantine history.
As one would expect, much retconning of Basil's suitability to be monarch was indulged in after his accession to the throne. There is a story of an infant Basil found sheltered by the shadow of an eagle, and he was also said to have first entered Constantinople via the middle portal of the city's Golden Gate, which was normally opened solely for imperial triumphs. [Source: Michael McCormick, Eternal Victory: Triumphal Rulership in Late Antiquity, Byzantium and the Early Medieval West, pp.152-3]
The elevation of an able peasant could and did also happen in China and Japan, as the result of taking leadership roles in successful rebellions. Liu Bang, founder of the Han dynasty (reigned 202-195 BC), Zhu Yuanzhang, founder of the Ming dynasty (reigned 1368-1398) and Toyotomi Hideyoshi, who became de facto ruler (though not emperor) of Japan (ruled 1585-1598) were all the sons of peasant families.
In the cases of Liu Bang and Zhu Yuanzhang (the latter of whom spent at least a couple of years living as a beggar), we can say that Chinese historiographical tradition lent significant support to usurpers from lower classes. Emperors were assumed to rule with the mandate of heaven; those who were unworthy of that mandate received warnings (comets, famines) and – it was thought – could eventually lose the mandate and be replaced by a more worthy successor. The practical impact of this idea was that all emperors were assumed to rule by divine favour until their overthrow; but the very fact of being overthrown was proof that they had lost the mandate of heaven, and that it had been transferred to their successor, whoever he was. This form of post hoc celestial legitimation of a new regime made it far easier from someone from a socially very inferior background to be accepted as emperor than would have been the case in Europe, where the stigma of being a usurper was often very great – witness the example of Henry IV of England, who never really overcame it; having started out as a usurper also defined, to a remarkably large extent, the whole reign and policy of Henry VII. (It's also worth noting that the word "peasant" has different connotations in Japan to those it has in European history. The peasant class incorporated quite prosperous tenant farmers, and so Hideyoshi's antecedents were probably significantly more promising than those of the others on my list; the village he came from is described as "a comparatively well-off community of peasants" by Mary Elizabeth Berry, Hideyoshi, p.8. That said, the barriers to social mobility in Japan were at least as daunting as those in place elsewhere; for any man lacking samurai ancestry to succeed as a military leader was pretty exceptional.)