The Spaniard had caused an upset when he defeated the world No 1 in the third round in Monte-Carlo last week, and he looked poised for a repeat.
But Ramos-Vinolas missed a chance to serve for the match and it was Murray who came through 2-6, 6-4, 7-6 (7/4) after two hours and 59 minutes.
In the semi-finals he will face fourth seed Dominic Thiem, who will be looking for a third British scalp of the week after knocking out Kyle Edmund and Dan Evans.
Murray lost the deciding set in Monte-Carlo from 4-0 up, and Ramos-Vinolas picked up where he had left off by winning five of the first six games.
Murray’s first-serve percentage in the opening set was just 35 and a string of unforced errors gave his Spanish opponent a helping hand.
There were more positive signs in the second set for Murray but still he was the one under the most pressure as Ramos-Vinolas showed why he is at a career-high ranking of 19.
The Scot faced 15-40 at 3-3 and then 0-40 at 4-4 but held his nerve to edge in front. And, with Ramos-Vinolas serving to stay in the set, Murray pounced to level the match.
He dropped serve again at the start of the decider but fought back once more to make it 2-2, with Ramos-Vinolas receiving treatment to his left foot after appearing to jar it trying to retrieve a Murray volley.
It was the Spaniard who edged ahead again, though, with a break at 4-4 only to play his worst game of the match serving for it. Into a tie-break they went, and this time Murray took control early on, winning the first four points. He lost the next three but ensured this one did not slip away, clinching victory on his second match point.
There are still things the 29-year-old needs to improve, not least his serve, with his first-serve percentage never climbing above 50. But Murray will have at least one more match to work on that before he heads to the key French Open warm-up events in Madrid and Rome.
Maria Sharapova needs just one more win to book her place in French Open qualifying after beating Anett Kontaveit to reach the semi-finals of the Porsche Grand Prix.
The 30-year-old is yet to drop a set in Stuttgart following her return from a 15-month doping ban and saw off the spirited challenge of Estonian qualifier Kontaveit 6-3, 6-4.
The ranking points Sharapova has collected mean she is already close to rejoining the top 250 on Monday, and victory in the last four on Saturday would guarantee a spot in the top 200.
That would be enough to earn her entry into the qualifying tournament at Roland Garros without the need for a wild card. The French Tennis Federation will announce whether the two-time French Open champion has been awarded a wild card into the main draw on 16 May.
After an understandably shaky start in her first match against Roberta Vinci, Sharapova has looked more and more like her old self. Kontaveit, ranked 73, appeared a kind draw for a last-eight clash but the 21-year-old has been in fine form and knocked out French Open champion Garbine Muguruza in the second round.
Kontaveit was not afraid to go toe to toe with Sharapova but, from 3-2, lost five straight games in a barrage of powerful hitting from the Russian.
Sharapova took control of the second set early and, although Kontaveit threatened a comeback, ultimately she could not get back on terms.
After breaking when Sharapova served for the match, Kontaveit had the chance to level but Sharapova stepped up once more and took her first match point with a thumping return. Sharapova next faces Kristina Mladenovic, who beat Carla Suarez Navarro 6-3, 6-2.
Meanwhile, Aljaz Bedene upset second seed Ivo Karlovic in the quarter-finals of the Hungarian Open for his 15th straight win.
The British No 4 broke the giant Croatian’s serve early in both sets on his way to a 6-4, 6-3 victory. He is through to his first ATP Tour semi-final since January 2016 and will face fellow qualifier Laslo Djere who defeated fourth seed Fernando Verdasco 2-6, 7-6 (7-4), 6-2.