All any villain really needs is a good therapist.

Daniil Medvedev is no different. The mercurial “villain of tennis,” who just beat Stan Wawrinka in the US Open quarterfinals on Tuesday, keeps his sports psychologist, Francisca Dauzet, stationed in his player box, in a seat usually reserved for family and friends.

Although Dauzet tells The Post that what she does with the love-him-or-hate-him Russian tennis great is “a secret,” tennis insiders say she’s likely there to help him keep calm — or at least put his rage to good use on the court, like his tennis forefathers John McEnroe and Roger Federer.

Over the weekend, Dauzet was shown on camera scrupulously taking notes on her client’s performance, wearing a shirt that said “Good Vibes.” But to those watching his matchup against Spain’s Feliciano Lopez, the vibes were anything but good. The lanky, 6-foot-6 23-year-old racked up $9,000 in fines Friday — and $19,000 in total during the US Open — for angrily throwing a towel at a ball boy, throwing his racket in the direction of the umpire’s chair and giving an increasingly jeering crowd the middle finger.

Upon his win over Lopez, Medvedev soaked in the boos from an American audience clearly eager to lob their (misplaced?) ire at this apparent Russian troll.

“Thank you all, guys, because your energy tonight give me the win,” he said sarcastically in a courtside interview Friday — which won praise from champ Naomi Osaka. “I want all of you to know, when you sleep tonight, I won because of you.”

Sounds like he’s had a breakthrough. His therapist might be inclined to agree.

“He [needed] to … grow up as a man and as a player. And you could see the results now,” says the Paris-based Dauzet, who’s worked with Medvedev for over a year. The two communicate in French, she says. She’ll likely work with him ahead of his Friday match against Bulgaria’s Grigor Dimitrov.

Dauzet adds that she was especially impressed with his ability to “transcend” a painful quadriceps injury during his match — “Maybe [he] feels something bad, physically, [but] with his mind, he can [transcend] and really be the same.”

Dauzet has had her work cut out for her, though. In a fit of rage after losing a match at Wimbledon in 2017, Medvedev threw coins from his wallet at the umpire, suggesting the official had been bribed. He later told Russian site GoTennis.ru that he wasn’t proud of this kind of behavior.

“I worked with a psychologist to solve this issue. And as you can see, I don’t throw any coins anymore.”

Experts say Medvedev likely needs some of that anger to succeed on the court — and it’s often the role of a sports psychologist like Dauzet to figure out how to harness it for good.

“You need to find what we call a controlled burn,” says Dan Gould, a professor of kinesiology at the University of Illinois at Urbana-Champaign who has consulted for the US Tennis Association. “Some players have a more fiery personality and they need to play with their emotions.”

“But,” he says, “let’s just say sponsors don’t want someone who’s giving the crowd the finger.”

More and more, tennis players like Medvedev are putting sports psychologists on their teams to help them gain an edge, or at least manage their emotions in the high-stress sport, says Larry Lauer, Ph.D., the mental skills specialist for USTA player development.

“With the level [Medvedev] is at, it’s often the mind that ends up separating them from their opponents,” Lauer says. “It wouldn’t surprise me if you would see more sports psychologists in the team box.”

Adds California-based sports psychologist Michelle Cleere, Ph.D., Medvedev now needs to find the right balance between getting riled up and using that emotion for motivation — without being a straight-up jerk.

“McEnroe used his anger and fed off the crowd, which worked for him some of the time,” she says. “Fans can love it but they can also hate it, and when they start hating it, it becomes quite problematic for someone who thrives on it.”

Medvedev, for his part, says he’s doing the work.

“I’m working to be better,” Medvedev said, a little more earnestly, on Tuesday. “Hopefully I will show the bright side of myself.”