When the suitors for the hand of Helen were gathered at the court of Tyndareus, Odysseus realised that the odds were very slim that he would become Helen's future husband. So, he advised the king to call for an oath, the Oath of Tyndareus, according to which all suitors would protect the groom and the bride no matter what the outcome would be. In exchange, Odysseus asked help to marry Penelope.
When Helen was kidnapped (or eloped, according to some accounts) by Paris of Troy, the Oath of Tyndareus was invoked and everyone was summoned to fight against the Trojans; Penelope had just given birth to Odysseus' son, Telemachus, but Odysseus was forced to leave in order to honour his pledge. The Trojan War lasted ten years, and it took Odysseus another ten to reach his homeland, Ithaca. When he arrived, he disguised himself as a beggar, to test whether his wife had remained faithful to him.
Indeed, Penelope had managed to keep all of her suitors at bay. She had told them she would choose a suitor once she finished weaving a burial shroud for her father-in-law, Laertes; however, every night, she would undo part of the shroud. Her plan was revealed by one of her servants, Melantho.
Penelope eventually appeared in front of the suitors and said that she would marry the suitor that would be able to string Odysseus' bow and shoot an arrow through twelve axe heads. She already knew that this was a task that only her husband would have been able to achieve. None of the suitors was able to complete the task, and a disguised Odysseus asked to try; after being successful, he revealed himself and killed the suitors with the help of his son, the goddess Athena, and two of his herdsmen. Penelope, still not believing that this was her husband, told him to command the servant to move their bed. Odysseus protested saying that it was impossible as one of the legs of the bed was part of a living olive tree. Penelope finally accepted that this man was who he claimed to be, and the couple were reunited.