Inter missed a flurry of chances in the first half hour, and Riccardo Sottil made them pay when he volleyed Cagliari ahead in the 42nd minute.
Romelu Lukaku broke away to score a third in stoppage time as Inter moved back into second place with 24 points from 11 games, two behind leaders AC Milan who play at home against Parma later on Sunday.
Antonio Conte's side win follows being eliminated from the Champions League at the group stage earlier this week.
Inter gave Christian Eriksen only his fourth league start of the season and his first since Oct. 31, but he faded and was taken off just before the hour.
The goal knocked Inter out of their stride, and they struggled to create openings in the second half.
Two minutes later, their corner was cleared to the edge of the area, where Barella met it with a powerful volley which left Cragno helpless.
Barella then provided the cross from which D'Ambrosio headed Inter into the lead seven minutes later.
Cragno joined the attack for a corner as Cagliari launched a desperate late offensive, but they were caught on the break and Lukaku was able to walk in the third in stoppage time for his ninth league goal of the season.