Cavani switched play with a long cross to Luis Suarez and continued his run to head home a pinpoint deep cross from the Barcelona forward and give Uruguay a seventh-minute lead.
Portugal defender Pepe made Uruguay pay for sitting back when he leapt unmarked to head in a cross from Raphael Guerreiro following a short corner to level the match at 1-1 in the 55th minute.
That was the first goal the twice World Cup champions had conceded in the tournament in Russia, but another moment of brilliance from Cavani put them back ahead seven minutes later at the packed Fisht Stadium overlooking the Black Sea.
The Paris St. Germain forward curled in a first-time right-foot shot from Rodrigo Bentancur's pass to beat Portugal goal-keeper Rui Patricio before limping off injured in the 74th minute as the Uruguay defence dug in to hold on to their lead.
Uruguay will play France in the last eight in Nizhny Novgorod on Friday and will wait with bated breath on the injury to Man-of-the-Match Cavani, who has scored three goals in the tournament.
Portugal, who won Euro 2016 in France, dominated possession but their attack did not have enough bite to break through the steely Uruguay defence twice.
They had 61 percent possession, played more than double the number of passes as Uruguay and had 20 attempts compared to six from their opponents.
Portugal Captain Cristiano Ronaldo cut a frustrated figure during the entire match and could not add to his four goals in the first two matches, failing to improve his record of failing to score in all six World Cup knock-out matches he has played.
The Real Madrid forward had an opportunity in the first half to score from a free-kick about 30 metres out but could only hit the wall.
Add commentComments will be edited (grammar, spelling and slang) and authorized at the discretion of Daily Mirror online. The website also has the right not to publish selected comments.