Andy Murray gained revenge on Spain's Albert Ramos-Vinolas but was pushed all the way in a gruelling three-hour encounter 2-6, 6-4, 7-6 (7/4) to make the Barcelona Open semi-finals on Friday.
Ramos-Vinolas beat the world number one on Murray's return from an elbow injury in the third round of the Monte Carlo Masters last week.
He threatened to repeat that upset when he served for the match in the third set.
However, Murray, who accepted a late wildcard to the event in the Catalan capital to gain match practice ahead of next month's French Open, battled back to edge out the world number 19 in a final set tiebreak.
Ramos-Vinolas is in the form of his life having risen to a career high ranking after reaching the final in Monte Carlo and he dominated the opening stages, taking five straight games after Murray started with a comfortable hold.
The second set went with serve for the first nine games, but Ramos-Vinolas was left to rue three missed break points to serve for the match as Murray held and then immediately broke for the first time in the match to level at one set all.
The Scot, though, failed to build on that momentum as he was broken in the first game of the third set.
However, Ramos-Vinolas had to take an injury timeout after twisting his ankle when leading 2-1 and Murray pounced to break back at 2-2.
Ramos-Vinolas had the chance to serve it out when he broke again for 5-4, but nerves seemed to get the better of him as three errors handed Murray the break back.
Murray raced out to a 4-0 lead in the tiebreak and saw it out as Ramos-Vinolas's efforts over the past two weeks finally began to take their toll.
The Wimbledon champion faces Dominic Thiem in Saturday's semis after the Austrian ended Japanese lucky loser Yuichi Sugita's unlikely run to the quarters 6-1, 6-2.
Sugita lost in qualifying and was only handed a place in the main draw after compatriot Kei Nishikori's late withdrawal with a wrist injury.
Thiem had far too much quality for the world number 91 as the Austrian wrapped up victory in under an hour on court.
Rafael Nadal's quest for a 10th Barcelona title also continues in Friday's quarter-finals when he faces Korean qualifier Chung Hyeon.