The Gospels narrate how Jesus was baptized in the Jordan by John the Baptist. The prophet poured water over Jesus' head in a similar way to how a priest pours water over the head of an infant in the Catholic Church.
However, what Jesus received was not the exact same as the sacrament of baptism.
Penitential act
Pope Benedict XVI explains the differences between the two types of baptism in a homily he gave on the feast of the Baptism of the Lord in 2011:
Although it was called “Baptism” it did not have the sacramental value of the rite we are celebrating today; as you well know, it was actually with his death and Resurrection that Jesus instituted the sacraments and caused the Church to be born. What John administered was a penitential act, a gesture of humility to God that invited a new beginning: by immersing themselves in the water, penitents recognized that they had sinned, begged God for purification from their sins and were asked to change wrong behavior, dying in the water, as it were, and rising from it to new life.
The baptism that John the Baptist administered was not a sacrament. The Church had not been born out of the side of Jesus Christ on the cross and so this baptism was a "precursor" to the sacrament of baptism.
Jesus, being sinless, did not need John's baptism, but went down into the water to become one with us, as Pope Benedict XVI explains:
The Baptism of Jesus, which we are commemorating today, fits into this logic of humility and solidarity: it is the action of the One who wanted to make himself one of us in everything and who truly joined the line of sinners; he, who knew no sin, let himself be treated as a sinner (cf. 2 Cor 5:21), to take upon his shoulders the burden of the sin of all humanity, including our own sin. He is the “servant” of Yahweh of whom the Prophet Isaiah spoke in the First Reading (cf. 42:1). His humility is dictated by the desire to establish full communion with humanity, by the desire to bring about true solidarity with man and with his human condition.
Jesus' baptism inaugurated his public ministry and laid the groundwork for what would become an essential sacrament of the Catholic Church.