Imagine two fierce legions who were always at war with one another, but when the king needed their services for his own battle, he made peace between them, so that both should carry out the orders of the king. Likewise, fire and water are hostile to each other, but when the time came to do war with Egypt.. "there was hail, and fire flaring up within the hail" (Exodus 9:24)
Midrash Rabbah