On 13 July 2017, Rami joined Ligue 1 club Olympique de Marseille on a four-year contract for a €6 million transfer fee. On 27 July, he made his competitive debut for Marseille, in their 2017–18 UEFA Europa League third qualifying round, first leg match against Oostende at the Stade Vélodrome, playing the full 90 minutes of the 4–2 victory. He made his Ligue 1 debut for Marseille on 6 August in their home match against Dijon, again playing the full 90 minutes of the match, which Marseille won 3–0. On 14 September, he headed home Dimitri Payet's corner to score his first competitive goal for Marseille in their 2017–18 UEFA Europa League group stage 1–0 home win over Konyaspor. On 3 May 2018, he played every minute of the Europa League semi-final second leg match away to FC Red Bull Salzburg which Marseille lost 2–1 after extra-time but won 3–2 on aggregate to secure a place in the 2018 UEFA Europa League Final which was played at the Parc Olympique Lyonnais in Décines-Charpieu, Lyon, France on 16 May 2018, against Atlético Madrid. Rami played the full 90 minutes of the final, which Atlético Madrid won 3–0.