The decision, which was taken by Rabat, shuts down the only land border between Africa and the European Union.
Spain's foreign ministry also said that Morocco had “suspended flights to and from Spain and all passenger transport by boat” in a move coordinated with Madrid.
Authorities in both enclaves issued a message late on Thursday urging all citizens currently located in Morocco to quickly return home.
“From 6:00 am (0500 GMT), the Beni Enzar border crossing will be closed so all citizens of Melilla who are currently in Morocco should return to the city as soon as possible,” the Melillan authorities wrote on Twitter, describing it as a “preventative measure”.
Authorities in Ceuta also confirmed the frontier closure.
Antonio Navarro, managing editor of the Madrid-based Atalayar, told AFP he had just managed to avoid being caught in the closures after travelling to Tangiers for work on Wednesday.
After hearing the borders were about to be shut, he rushed back to Ceuta during the night and was able to catch a pre-dawn ferry to the southern Spanish port of Algeciras.
“I don't want to go to Madrid, to ground zero,” he admitted, saying he would work from his parents' home in the southern city of Sevilla.
Spain is one of the worst-hit countries in Europe, with more than 4,200 cases and 120 dead, and most cases in Madrid.