Moralez finished with a goal and an assist as New York won the battle between two heavyweights from the East and reached the next stage of the tournament.
They next face the winner of another knockout round contest on Tuesday between the Portland Timbers and FC Cincinnati.
Jesus Medina, in the fifth minute, and Castellanos, in the 55th, gave New York City a 2-0 lead before Moralez scored the third in the 81st at the ESPN Wide World of Sports Complex in Florida.
Patrick Mullins scored the lone goal for Toronto in the 87th minute in the much-anticipated rematch of the Eastern Conference semi-final from last year.
Sunday’s win was a measure of revenge for New York who came into the knockout round through the backdoor as a third place team in the group stage.
They lost in the playoffs last year to Toronto but can now claim bragging rights in this tournament.
Castellanos got the crucial second goal after Moralez released him down the left flank with a long ball from midfield. Castellanos collected and created some space before hammering a shot inside the far post.
Medina had taken advantage of a poor clearance to open the scoring for New York and Moralez sealed victory by finishing off a Herber back heel.
The “MLS is Back” tournament is being staged at a single location in Orlando, Florida after a four-month shutdown because of the coronavirus pandemic.
The MLS is Back champion will earn a place in the 2021 CONCACAF Champions League.