Madrid: World No 1 Novak Djokovic had to rally in both the first and second sets but managed to pull out a 7-6 (7-2), 7-6 (7-4) victory over Dominic Thiem in first Madrid Open men's semifinal.

The 31-year-old Djokovic, who has won the last three Grand Slam events (2018 Wimbledon, 2018 US Open and 2019 Australian Open) but struggled with his game in March and April, earned his best clay-court victory of the season in a match filled with grueling baseline rallies, Efe news reported.

The Serbian stayed calm throughout the match on Saturday and took advantage of the few opportunities he created against Thiem's serve.

The fifth-ranked Austrian, who defeated Spanish world No. 2 Rafael Nadal en route to capturing last month's Barcelona Open and came into the contest with an eight-match winning streak, struck first with a service break in the third game.

But Djokovic managed to break back thanks to some phenomenal retrieving and then saved two break points in the crucial ninth game before the set came down to a tiebreaker, which the Serb won easily thanks to Thiem's several unforced errors.

The point of the match came in the fifth point of the tiebreaker, when Djokovic executed a remarkable, on-the-run backhand defensive lob off a Thiem backhand overhead and then won the point - and grabbed a 4-1 lead - when the Austrian sent a forehand long.

The second set was nearly a carbon copy of the first, with Thiem taking a 4-2 lead with a service break but then succumbing to Djokovic's returning prowess in the ensuing game.

The Serbian appeared to strike the crucial blow when he broke the Austrian's serve once again in the 11th game to take a 6-5 lead, but a costly double fault on break point meant the second set was also decided by a tiebreaker.

A double fault by Thiem gave Djokovic a mini-break lead at 5-3, and the Serb finished off the victory a few points later when Thiem shanked a backhand nearly into the stands.

"I played the best match of the clay-court season so far, for me, against arguably the best tennis player in the world on this surface, so far (this season)," the world No. 1 was quoted as saying on the ATP Tour's Web site.

Thiem, who still remains one of the top three favorites at the upcoming French Open along with 2016 winner Djokovic and 11-time champion Nadal, took the positives from the match and this ATP Tour Masters 1000 event.

"I never complain about a 1000 semi-final. It's a very good result," Thiem said. "I beat three very good players (including Roger Federer on Friday) and I lost to Djokovic."

Djokovic, who won the Madrid Open in 2011 and 2016, will take on either Nadal or Greek rising star Stefanos Tsitsipas, the world No. 9, in Sunday's final.