The European champions made the trip to North Africa to take on the Segunda Division B outfit in the first leg of their last-32 clash, and it proved to be a comfortable 90 minutes for the visitors.
Julen Lopetegui was sacked as head coach of Los Blancos following the 5-1 defeat at Barcelona on Sunday, but the capital giants were back to winning ways in the Copa del Rey courtesy of goals from Karim Benzema, Marco Asensio, Alvaro Odriozola and Cristo Gonzalez.
Real Madrid had the first opportunity of the match in the fifth minute when Vinicius Junior delivered a dangerous cross into Asensio, but the Spaniard could not find a route past Melilla goalkeeper Dani Barrio.
The rain started to fall in the early stages of the match, which created a slick surface. Real Madrid were not having things all their own way, however, as the hosts continued to impress in the wide positions.
Benzema had a shot blocked in the 23rd minute during a period where the visitors were having a lot of the ball, and Melilla goalkeeper Barrio had to keep out a deflected Lucas Vazquez strike with the pressure firmly on.
Los Blancos ultimately made the breakthrough in the 28th minute when Odriozola drove down the right before delivering a low cross into Benzema, who simply could not miss from close range.
Asensio forced Barrio into a smart save in the 37th minute, before the Melilla goalkeeper kept out an effort from Lucas as Real Madrid looked for a second before the break.
Vinicius Junior - making his first start for the European champions - had another chance late in the first period, but the Brazilian's effort just curled wide of the far post.
Real Madrid did find a second just before the half-time break, however, with Asensio firing a low Vinicius Junior cross into the bottom corner of the net.
Sergio Ramos and Benzema were both replaced at the interval, with Solari having one eye on this weekend's La Liga clash with Real Valladolid.
Not too much occurred in the first 15 minutes of the second period, although Melilla were seeing more of the ball as they attempted to fight back on home soil.
Dani Ceballos should have scored a third for Real Madrid just past the hour after being freed inside the Melilla box, but Barrio was on hand to make another smart save, before keeping out a Marcos Llorente strike moments later.
Vinicius Junior rattled the home side's crossbar in the 72nd minute, before Ruano just missed the post with a low attempt down the other end of the field.
Real Madrid had their third in the 79th minute when Odriozola smashed home from close range following a period of pin-ball inside the Melilla box.
The visitors were not finished, however, and added a fourth in the second minute of additional time at the end of the 90 when substitute Gonzalez headed home from close range for his first senior goal on his debut.
MELILLA (4-4-2): Barrio; Chakla, Segura, Carrion, Mahanan; Ruano, Martin, Garrido (Bueno 84'), Martinez (Brahim 75'); Otegui, Qasmi (Martin 70')
REAL MADRID (4-3-3): Navas; Odriozola, J Sanchez, Ramos (Nacho 46'), Reguilon; Ceballos, Llorente, Asensio (Gonzalez 83'); Lucas, Benzema (Valverde 46'), Vinicius