Here's a more detailed account:
Laius, the king of Thebes, was warned by an oracle that he would father a son who would cause his downfall and take his throne. Fearing this prophecy, Laius ordered that any male children born to him and his wife, Jocasta, should be killed. However, Jocasta, unable to bear the thought of killing her own child, decided to save one son by piercing his ankles and leaving him to die exposed on a mountainside.
The child was found by a shepherd and taken to the king of Corinth, Polybus, who raised him as his own and named him Oedipus. Oedipus grew up unaware of his true parentage. Years later, an oracle informed him that he was destined to kill his father and marry his mother. Horrified by this revelation, Oedipus left Corinth to avoid committing such a heinous act.
On his journey, Oedipus encountered Laius at a crossroads. They argued, and in a fit of anger, Oedipus killed Laius without knowing that he was his father. He then proceeded to Thebes, where he unwittingly fulfilled the rest of the prophecy by solving the riddle of the Sphinx and becoming the new king. He subsequently married Jocasta, who was unaware that she was his biological mother.