Croatia, reduced to 10 men early in the second half when Marko Rog received a second booking, seemed to be heading for a draw in Split on Wednesday (AEDT).
Mateo Kovacic opened the scoring in the 29th minute before curling in from the edge of the box after goals from Ruben Dias and Joao Felix had put Portugal ahead.
But Livakovic endured a 90th-minute nightmare, fumbling a corner to the feet of Dias, who completed his double to snatch the points, yet Croatia avoid the drop due to France's win over Sweden.
Diogo Jota and Cristiano Ronaldo went close as Portugal turned the screw, but the visitors had Dias to thank when he blocked Mario Pasalic's goal-bound effort at the other end.
Yet Dias could not prevent Croatia from opening the scoring – Kovacic lashing home at the second attempt after having his initial shot from Pasalic's cross blocked.
Portugal should have been two down eight minutes later, only for Josip Juranovic to head wide from inside the six-yard box, and Danilo Pereira would have made Croatia pay if not for Livakovic's instinctive stop.
But Portugal had its equaliser eight minutes into the second half.
Rog was shown a second yellow card for a foul on Ronaldo, whose free-kick was parried out by Livakovic and Ruben Semedo squared for Dias to add insult to injury by prodding in.
Portugal was in front on the hour-mark, with Joao Felix on hand to tuck in from Jota's lay off, yet Croatia defied their numerical disadvantage to hit back when Kovacic curled a low strike into the bottom-left corner.
Bernardo Silva squandered a golden chance to win it for Portugal, but his blushes were swiftly sparred by Livakovic.
The goalkeeper charged out to claim Joao Moutinho's corner, only to drop it after making contact with Dejan Lovren, enabling Dias to snatch victory.