Reigning US Open champion Medvedev had to produce his best tennis to survive a tense first set as a confident Cilic sent across nine forehand winners and won nearly three-quarters of his service points.
The awed crowd inside Madrid Arena was reduced to pin-drop silence as the 1.98-metre titans went into a tiebreak, where Medvedev relied on his backhand to prevail despite an ill-timed double fault.
Cilic showed signs of fatigue in the second set as the world No 2 broke his serve in the fourth game before running away with the momentum, dropping just one of his first-serve points.
"I'm happier for the team than for myself," Medvedev said. "I'm just happy to be part of this team and be able to bring the points."
Medvedev got a standing ovation from the crowd and made peace with the Spanish fans following a week of animosity after Russia eliminated Spain in the group stage of the Davis Finals.
"I loved the atmosphere. It was a really amazing two weeks because it’s never easy to come here in the end of the season and compete. For sure it was the best two weeks of my career," Medvedev said.
Earlier world No 5 Andrey Rublev beat Borna Gojo 6-4 7-6(5) to give the Russian Federation a 1-0 lead.
Russia's third title equals the Czech Republic and Germany in seventh place on the all-time list of Davis Cup winners.
World number 279 Gojo entered the match as the big surprise of the tournament and a favourite of the Spanish crowd.
He was unbeaten in the finals with three victories over world number 61 Alexei Popyrin of Australia, number 27 Lorenzo Sonego of Italy, and 33rd-ranked Serbian Dusan Lajovic.
But Rublev played a near-flawless match, overpowering Gojo with strong serving to keep the Croatian on the back foot.
Gojo battled hard but Rublev broke his serve at the fourth attempt before taking the opening set in 35 minutes.
Gojo fired down 11 aces, and the second set went to 6-6 before Rublev edged the tiebreaker to clinch victory.
"It was super tough and I felt a lot of pressure, but it's good to put my country in the lead," Rublev told reporters.
Russia are the fourth nation to win both Davis Cup and Billie Jean King Cup titles, after the women's team won that event in Prague last month with a 2-0 victory over Switzerland in the final.