Real cut loose in the Bernabeu after halftime with goals from Beckham, Ronaldo, Ruben del la Red and Van Nistelrooy. Ecija, who had held Real 1-1 in the first leg, managed to net a consolation goal through defender Mario.
Earlier Celta, who had beaten Real 2-1 away on Sunday, fell to Alaves at home with Brazilian midfielder Wesley scoring the only goal of the tie, early in the second half.
Alaves join three other non-Primera Liga sides in the last 16 of the Cup - Rayo Vallecano, Valladolid and Malaga.
Third division Rayo knocked out Cup holders Espanyol 2-1 on aggregate on Wednesday, while second division sides Valladolid and Malaga saw off Gimnastic and Real Sociedad respectively.
One game remains to be played in the fourth round after Levante's second leg with Atletico Madrid on Tuesday was postponed due to the poor state of the pitch. A date for the rematch has yet to be agreed.
RONALDO GOAL
Real coach Fabio Capello put out an attack-minded line up which had Ronaldo and Van Nistelrooy starting up front together for the first time this season, and Jose Antonio Reyes and Beckham on either flank.
But they failed to make much of an impression early on against a well organised Ecija who had two clear chances to take a surprise lead in an otherwise dull first half.
But three minutes after break Van Nistelrooy was foiled in a one-on-one and the ball broke free for former England captain Beckham to drive low into the empty net.
With the visitors forced to come out and chase the game Real were able to pick them off at will.
After 68 minutes Ronaldo swivelled and fired into the corner for his first goal since scoring in a 1-1 draw against Real Sociedad on April 8, and in the 72nd Reyes was pulled back in the area for a penalty.
Van Nistelrooy made no mistake from the spot but five minutes later Ecija's travelling fans were rewarded with a goal as Mario flicked a header inside Real's far post.
Almost immediately it was 4-1 as Van Nistelrooy scored with an overhead kick from close range, and substitute De la Red finished off with a fine long range effort at the end.