Silva crosses in for Guedes, but Godin gets there first to head the danger away.
2 minutes of Stoppage time!
Cavani had already put Uruguay in front early on, only for Pepe to head Portugal level in the 55th minute in a thrilling contest that was not the battle of attrition many predicted. Suarez fires the ball past the Portugal wall but Rui Patricio leaps to his left to save the ball.
Portugal hasn't been able to respond despite a few opportunities including a Ronaldo free kick.
The five points were enough to move Portugal onto the knockout round.
While Uruguay is advancing, it now must be concerned with the status of Cavani after he limped off the field and immediately called for a substitute.
Cristiano Ronaldo is shown a yellow card by referee Cesar Ramos.
2 minute: Free-kick to Portugal after Pepe goes down in a challenge from Cavani.
But parity did not last long, Cavani steering a brilliant curling finish into the corner after 62 minutes following Bentancur's beautifully-weighted pass into his path.
A narrow victory against Morocco was their only win in their first three matches and they will have to improve against Uruguay, who are unlikely to allow spaces behind their defence.
Portugal pressed for an equaliser and Silva volleyed over after Muslera had spilled Raphael's cross.
But by defeating the reigning European champions, the two-time World Cup winners will face France in Nizhny Novgorod on Friday with hopes of making it to the semifinals and keeping alive the prospect of an all-South American clash in the final.
If you have cable or satellite then use the Fox Sports Go website or mobile app to login with your provider's credentials and access the Fox live stream for Portugal vs Uruguay.
Paris Saint-Germain striker Cavani curled home a superb 62nd-minute victor to settle a thrilling second round duel in Sochi which sends Uruguay into a quarter-final against France next Friday.