Cilic, the runner-up at the 2017 championships, was two sets to the good in the third-round match on Court 1 on Sunday (AEST) against the No.2 seed.
Yet Medvedev, who won his first ATP Tour title on grass in Mallorca this year, responded in style to win a grand slam match after losing the opening two sets for the first time.
The Russian triumphed 6-7 (3-7) 3-6 6-3 6-3 6-2 to stretch his grass-court winning streak to seven matches and reach Wimbledon's second week for the first time in his career.
Medvedev took David Goffin to five sets at this tournament two years ago only to suffer defeat, and he was worried such a scenario could repeat itself when his 5-0 lead in the decider quickly became 5-2.
"It was an unbelievable match," he said on court. "I think tennis fans always enjoy watching players come back from two-sets-to-love down and for it to be five sets. I certainly do so when I watch tennis on the TV.
"It's my first comeback [from two sets down], and actually what's amazing is against David Goffin at Wimbledon in 2019, I was two-sets-to-love down and I had a break in the fifth set, but I lost. So when I left the court after the fourth set today, I told myself, 'It's not going to be another one of those'.
"So I'm really happy. When I was 5-0, 40-0 up at the end and Marin came back to 2-5, I thought to myself, 'Again!' Marin is an amazing player and for the first two sets he basically destroyed me."
Medvedev joined compatriots Andrey Rublev and Karen Khachanov in the second week, making this the first year in which three Russian men have reached this stage at Wimbledon in the Open Era.
Medvedev will face 14th seed Hubert Hurkacz next and could meet Roger Federer in the quarter-finals.