Rafael Jodar has admitted he needs to improve his behaviour on court after apologising for swearing at a ballboy at the Shanghai Masters, where he made history by reaching the semi-finals.

The 20-year-old Spaniard recovered from a set down to defeat Casper Ruud 4-6, 6-4, 6-3 on Friday, becoming the youngest player to reach the last four in the tournament's history.

The victory came in Jodar's first match since he received a warning for unsportsmanlike conduct after angrily demanding a towel from a ballboy during his fourth-round match against Botic van de Zandschulp.

Jodar admits he was wrong after ballboy incident

Jodar lost the opening set against Van de Zandschulp on Wednesday before shouting an expletive at the ballboy while asking for a towel. He went on to win the match 6-7, 6-4, 6-2, but the incident prompted a warning from the chair umpire.

Reflecting on his behaviour after beating Ruud, Jodar accepted that frustration was no excuse for how he had treated the ballboy.

"I was just frustrated with myself and I couldn't control my emotions at that point of the match," he told reporters.

"After the match I thought about it and I shouldn't have done that to the ballkid. It was my mistake," he added, saying he wanted to apologise to the ballboy.

Jodar acknowledged that learning to manage his conduct was another part of his development as a professional.

"As I'm learning how to do the forehand, how to do the backhand, how to serve, I'm also learning how to behave on court, and there's still a lot of things," he said.

"I'm not perfect."

Jodar makes Shanghai Masters history

The Spaniard's run in Shanghai has been one of the standout stories of his breakthrough season. Having started the year ranked 168th in the world, he has climbed to No. 13 and continued his progress with a series of resilient performances in China.

Against Ruud, Jodar again had to recover after losing the first set. He raised his level in the second and third sets to complete the comeback and secure his place in the semi-finals.

Ruud saved three match points before a double fault ended the contest, handing Jodar the victory.

The Spaniard will face either Daniil Medvedev, the 2019 Shanghai champion, or American Tommy Paul for a place in the final.

Jodar's record-breaking run has brought growing attention to his talent. His comments after the Ruud match also showed that he recognises his progress must extend beyond his tennis, with his behaviour under pressure another area he wants to improve.