Ounahi gave world No.6 ranked Morocco the lead in the 50th minute and added another in the 82nd minute on the break before Soufiane Rahimi scored against a pressing Canada in the eighth minute of stoppage time.
"We are no longer a surprise," coach Mohamed Ouahbi said through a translator. "Now when people talk about Morocco we're a major contender and it's a great source of pride. I think it's only the beginning and I hope we continue to have runs like this.
"We want to keep going. We don't want to stop."
Canada's dream run ended after failing to take advantage of early domination. They had never before this year advanced out of the group stage, but did so and won their first knockout match, 1-0 against South Africa in the round of 32.
After a listless first half, Morocco stunned Canada with a goal from nowhere with only their second shot of the match.
Achraf Hakimi lined up for a free-kick to the right of the goal after a yellow card, the seventh of the match, to Canada's Luc de Fougerolles for a sloppy foul on Soufiane Rahimi.
Hakimi put the ball on the ground to Ounahi on the edge of the box and he quickly one-timed a shot to the right corner with the Canadians caught a step behind.
In the 77th minute, Canada's Jonathan David sent a free-kick from outside the box over the bar and a minute later, team-mate Tajon Buchanan's long strike forced a diving stop at the left post by Moroccan goalkeeper Yassine Bounou.
That proved crucial when Ounahi took a layoff pass from Brahim Diaz to make it 2-0 and Rahim wrapped up the win late on.
However, Morocco, suffered a major blow in the 22nd minute when leading scorer Ismael Saibari had to leave with a possible hamstring injury.
Now unbeaten in 34 matches, Morocco will next play on July 9 in Boston against the winners of the France-Paraguay match later on Saturday.
Canada coach Jesse Marsch shared his postgame message to the team.
"I told them that I was proud of them and I challenged them to understand that we can play like this all the time against the best teams in the world," he said. "We can be better on the day. And then the challenge is, can we hold that standard for 90 minutes?"