Exodus 13:15

And it came to pass, when Pharaoh would hardly let us go, that the LORD slew all the firstborn in the land of Egypt, both the firstborn of man, and the firstborn of beast: therefore I sacrifice to the LORD all that openeth the matrix, being males; but all the firstborn of my children I redeem.

When Pharaoh hardened himself and would hardly let Israel go, the Lord struck dead every firstborn throughout the land of Egypt, both the firstborn of man and the firstborn of beast. That sweeping judgment on Egypt's eldest sons and firstling animals became the reason given for what Israel was to do afterward with its own firstborn. In memory of that act, every male that first opens the womb was to be set apart and sacrificed to the Lord, while every firstborn son among the children was not sacrificed but redeemed with a payment.

The firstborn thus devoted, together with other firstfruits, were given to God and then directed to the support of the priests. By this arrangement God was acknowledged as first, as the owner of the fields and flocks and herds, while the people held their increase as stewards of what He had provided.