Barella will spend the 2019-20 season at San Siro before joining the Nerazzurri permanently on a five-year contract.
Inter are reported to have paid a €12 million loan fee for Barella, who will then cost €25m next year, with the deal including a potential €13m in add-ons, taking the transfer to a total value of €50m (£45m/$56m).
"He's not shy on the pitch, he's not afraid," Inter said of Barella in a club statement. "He gets involved in tackles on many occasions because he wants to win back the ball, because he wants to win.
"Last season, he was the player who regained possession the most out of all the players in the league, while he's also the midfielder who has won the most duels in the past two seasons."
Cagliari said goodbye to Barella, who made 112 appearances for the club, in an emotional statement.
"In the life of every boy, sooner or later the time comes to leave home to continue on his own journey," Cagliari said on the club's official website. "It is with a touch of emotion that the club sees Nicolo leaving today.
"Born in Cagliari, a supporter of his city team, he grew up carrying more and more responsibility on his shoulders: with Sardinian pride he developed the temper of the leader, without trembling in front of the most difficult challenges and even wearing the captain's armband.
"This Rossoblu home will always be yours too. Goodbye, Nicolo."