The 24-year-old defender was part of the Rennes team that upset Paris Saint-Germain at the Stade de France in April. He started for Algeria as they won the African Cup of Nations in Egypt, beating Senegal in the final.
He began his career with Paradou in Algiers and played for Lierse in Belgium and Montpellier. He also had a trial with Arsenal, playing one reserve game. He joined Rennes in 2016.
He could make his Moenchengladbach debut in the opening round of the Bundesliga at home to Schalke on Saturday.
Reports estimated that the fee was 10 million euros ($11.2 million).
"Ramy is the player we've been looking for our squad," Moenchengladbach sporting director Max Eberle told the club web site. "He can be used as a left back or central defender and brings a lot of experience from three successful years with a very good club from the French Ligue 1."
Moenchengladbach won the last of their five Bundesliga titles in 1977 and finished fifth last season.