Andy Murray avoided losing to Albert Ramos-Vinolas for the second successive week with a battling performance at the Barcelona Open.
The Spaniard had caused an upset when he defeated the world number one 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.