The Belgium international, who was also a reported target of Juventus, Napoli and AC Milan, has also signed a contract with the Giallorossi that would tie him to the club until June 2018 if the move is made permanent.
A statement from Roma read: "Roma announces that it has agreed with Cagliari to sign Nainggolan temporarily until the end of the season subject to a fee of three million euros.
"As part of the agreement, Roma holds the right to acquire the player on a permanent basis at the end of the season for a value of six million euros."
Nainggolan has scored two goals in 17 league appearances for Cagliari this season.
The 25-year-old could make his Roma debut on Sunday against Genoa at the Stadio Olimpico.