The 30-year-old Russian took a while to find his range on Court Two against Merida, 21, a busy all-court player, who broke into the top 100 this year and is now ranked 84th in the world.
For much of the match, Medvedev, seeking a second Grand Slam trophy after winning the US Open in 2021, looked as though he found tennis a chore.
"I was lacking rhythm a little bit in the beginning," Medvedev said in a courtside interview.
"He was returning really well so being solid on my serve was a good feeling," the lanky 1.98-metre Russian added.
"My serve didn't really let me down today."
Medvedev yelled with triumph and relief in the fourth set when he twice broke the Spaniard's serve and applauded the crowd when he took the match with a big serve that Merida could only tip into the net.

And it was a smiling Medvedev who told reporters later he was happy with the way he improved during the match.
"(I) was finding solutions, better shots. So pretty happy about it, and looking forward for what's next."
Medvedev will meet either 28th-seeded American Brandon Nakashima or German veteran Jan-Lennard Struff in the third round.
Medvedev, a former world number one, lost in the first round at the French Open this year but said ranking was not his priority.
"For me, motivation is to try to play my best, maybe win here, and then you get 2,000 points. Then ranking is always secondary, because it comes with good results."
He said anything was possible in sport.
"I always believed in myself and sometimes after some losses this belief drops. Sometimes after some wins this belief goes higher.
"Once you're still in the tournament and you didn't lose, I always believe I can win, beat everyone and be the best."
See all the stats from the match here
Wimbledon 2026
Wimbledon is taking place from June 29th to July 12th at the All England Club in south-west London. With 128 players in the draw, it is the third of the four Grand Slams of the tennis season and the only one played on grass.
Men's singles draw and results | Women's singles draw and results | All you need to know about the tournament | Find all our Wimbledon coverage here
