These companies, which do not have offices in Russia, have become a vital resource for opposition groups and refuse to hand over user data to governments.
The use of Russian data centres would make them and other Internet companies subject to Russian laws on government access to information.
The Kremlin said the law was aimed at "improving the management of personal data of Russian citizens on computer networks" and that companies which do not comply with the legislation would be blocked.
The law could also cause problems for Russian companies such as tourism websites and airlines that rely on foreign-based online booking services.
More From This Section
Russia's Association of Electronic Communication (RAEC), a group that lobbies on behalf of Internet companies, warned earlier this month that "many global Internet services would be impossible" under the new law.
Internet companies have also warned that the two years before the measures come into force is not sufficient time for them to find or build data centres on which to store the data.
It is also in line with other recent Internet restrictions, including a requirement for bloggers to register as media if they have more than 3,000 followers and a law directed against "extremist" language that could see Russians go to jail for up to five years for retweeting "offensive" information.