People often try to apply human (secular) morality to God, with the inevitable conclusion that God is a monster. Instead, start with the certainty that God is both good and just, and consider His actions in light of His plans for humanity.
By killing the firstborn of Egypt, God was both...