Ranieri's Cagliari make greatest comeback in Serie A history
"I always say give everything until the end of the game. I hope that this victory will be a milestone," said manager Claudio Ranieri, whose side had started the day bottom of the table and had not won in their opening nine games.
The Sardinian team found themselves 3-0 behind in the 49th minute after letting in a goal by Marco Brescianini and a first-half brace by Matias Soule.
Their comeback did not begin until the 72nd when substitute Gaetano Oristanio scored and four minutes later Antoine Makoumbou made it 3-2.
Second-half substitute Pavoletti, levelled the tie in the 94th minute and two minutes later grabbed the winner.
Pavoletti then turned saviour at the other end, clearing off the line from a late Frosinone header as Cagliari won their first game of the season and climbed off the bottom of the table.
No team had ever gone on to win a Serie A game when 3-0 down going into the final 20 minutes.
Perugia came close in 2001 when 3-0 down to Bari, scoring for 3-1 in the 67th minute before going on to win 4-3.
In 1942, Torino came from 3-0 down against Napoli to win 5-3 but their comeback began in the 42nd minute, while in 1949 Inter Milan won a derby game with AC Milan 6-5, having been 4-1 down but having pulled back to 4-3 by halftime.
In 2011, AC Milan beat Lecce 4-3 after being 3-0 down at the interval, with Kevin-Prince Boateng scoring the first goal of a hat-trick in the 49th minute.
The same year, Genoa began a comeback from 3-0 down to AS Roma in the 52nd minute before winning 4-3. In 2021, Hellas Verona also pulled back the first goal in the 52nd minute after being 3-0 down to Venezia and won 4-3.