As the Catechism of the Catholic Church explains, “Holy Baptism is the basis of the whole Christian life, the gateway to life in the Spirit (vitae spiritualis ianua), and the door which gives access to the other sacraments. Through Baptism we are freed from sin and reborn as sons of God; we become members of Christ, are incorporated into the Church and made sharers in her mission: Baptism is the sacrament of regeneration through water in the word” (CCC 1213).
In normal circumstances, a bishop, priest or deacon is the ordinary minister of the sacrament. However, in an emergency, anyone can baptize a person who wants to be baptized.
In case of necessity, anyone, even a non-baptized person, with the required intention, can baptize, by using the Trinitarian baptismal formula. The intention required is to will to do what the Church does when she baptizes. The Church finds the reason for this possibility in the universal saving will of God and the necessity of Baptism for salvation. (CCC 1256)
Adults who are dying can be baptized if they request it, by anyone who is present. Fr. Paul de Ladurantaye explains in the Arlington Catholic Herald exactly how this is done.
In the case of necessity (e.g., the danger of death), the person who baptizes pours water three times over the candidate’s head, or immerses the candidate three times in water, while simultaneously pronouncing the baptismal formula: “N., I baptize you in the name of the Father (the minster pours water or immerses the first time), and of the Son (the minister pours water or immerses a second time), and of the Holy Spirit (the minister pours water or immerses a third time).” A lay person who administers an emergency baptism must at least have the intention to do what the Church does when baptizing. It is also desirable that, as far as possible, one or two witnesses to the baptism be present.
It must be kept in mind that this type of baptism performed by laypeople should only be administered to people in an emergency situation. If the person recovers and returns to full health, then that person should present themselves to the nearest parish and explain their situation so that they can be fully welcomed into the Catholic Church.