Exodus 1:15-16, 22:
And the king of Egypt spoke to the midwives of the Hebrews: of whom one was called Sephora, the other Phua, Commanding them: When you shall do the office of midwives to the Hebrew women, and the time of delivery is come: if it be a man child, kill it: if a woman, keep it alive...
...Pharaoh therefore charged all his people, saying: Whatsoever shall be born of the male sex, ye shall cast into the river: whatsoever of the female, ye shall save alive.
As to the slaughter of the Innocents in the New Testament, first some background: Herod the Great, the Governor of Galilee, was an Idumean Jew whom History describes as an extremely cruel man: he was a man who killed several of his wives and his own sons when he suspected they were plotting against him. Challenges to his power were met with a swift and final response, and he even tried to ensure that his cruel campaigns survived him when he arranged that on the day he went on to his eternal reward, hundreds of men in the area would be killed so that there would be mourning at his funeral. Though this arrangement was never carried out, it speaks well of Herod's nature.
And during this tyrant's reign, the Magi -- whose adoration of Baby Jesus is remembered on the Epiphany (6 January) and its Eve (Twelfthnight) -- saw the Star of Bethlehem and went to Jerusalem, asking where the new King of Jews may be found. Herod heard of their asking around about the newborn King and, calling the high priests to find out about this this Child, was informed that it was prophesied that the Child would be born in Juda.
Threatened by this prophecy, he sent for the Magi to find the Child and report back so he could go and "worship," too. The Magi found Jesus but, knowing Herod's heart after having it revealed to them in a dream, didn't go back to tell Herod of His whereabouts.
Meanwhile, the Holy Family, warned through St. Joseph who was visited by an angel in a dream, makes their flight into Egypt.
Herod became enraged at the Wise Men's "betrayal," and killed all the baby boys in Bethlehem who were two years old and younger.
The fourth day of Christmas commemorates these baby boys, who are considered martyrs -- the very first martyrs (St. Stephen, whose Feast was commemorated 2 days ago, was the first martyr of the Church Age). As Bethlehem was a small town, the number of these Holy Innocents was probably no more than 25, but they are glorious martyrs who died not only for Christ, but in His place. Vestments will be red or purple in mourning, and the Alleluia and Gloria will be suppressed at Mass.
While it is easy to get lost in the nightmare of what happened to the Innocents, it's to be remembered that they ultimately triumphed! They are Saints of God, as this painting by William Holman Hunt shows. The Innocents are seen with the Holy Family, in spirit, during the Family's Flight to Egypt:
A tiny child is born, who is a great king. Wise men are led to him from afar. They come to adore one who lies in a manger and yet reigns in heaven and on earth. When they tell of one who is born a king, Herod is disturbed. To save his kingdom he resolves to kill him, though if he would have faith in the child, he himself would reign in peace in this life and for ever in the life to come.
Why are you afraid, Herod, when you hear of the birth of a king? He does not come to drive you out, but to conquer the devil. But because you do not understand this you are disturbed and in a rage. To destroy one child whom you seek, you show your cruelty in the death of so many children.
You are not restrained by the love of weeping mothers and fathers mourning the deaths of their sons, nor by the cries and sobs of the children. You destroy those who are tiny in body because fear is destroying your heart. You imagine that if you accomplish your desire you can prolong you own life, though you are seeking to kill Life himself.
The children die for Christ, though they do not know it. The parents mourn for the death of martyrs. The Christ child makes of those as yet unable to speak fit witnesses to himself. But you, Herod, do not know this and are disturbed and furious. While you vent your fury against the child, you are already paying him homage, and do not know it.
To what merits of their own do the children owe this kind of victory? They cannot speak, yet they bear witness to Christ. They cannot use their limbs to engage in battle, yet already they bear off the palm of victory.-- Saint Quodvultdeus from a sermon about the Holy Innocents (H/T Angela Hebert for finding this @ Steve Smith's Saint Quote of the Day)