Andy Murray has told how playing tennis helped him to cope in the aftermath of the Dunblane massacre.

The tennis star - who rarely broaches the the subject of the shooting - revealed how the sport helped him to deal with “anxiety” following the tragedy in a rare emotional interview set to air later this week.

Both Murray and his brother Jamie were present at Dunblane Primary School when Thomas Hamilton murdered 16 children and a teacher on March 13, 1996.

In the interview, part of a documentary about his recovery from injury, Murray also revealed that he knew Hamilton growing up as a child.

“You asked me a while ago why tennis was important to me,” he said. “Obviously I had the thing that happened at Dunblane. When I was around nine. I am sure for all the kids there it would be difficult for different reasons.

“The fact we knew the guy, we went to his kids club, he had been in our car, we had driven and dropped him off at train stations and things.

“Within 12 months of that happening, our parents got divorced. It was a difficult time that for kids. To see that and not quite understand what is going on.”

With his voice quivering, he added: “And then six to 12 months after that, my brother also moved away from home. He went away to train to play tennis. We obviously used to do everything together. When he moved away that was also quite hard for me.

“Around that time and after that, for a year or so, I had lots of anxiety but that came out when I was playing tennis. When I was competing I would get really bad breathing problems. My feeling towards tennis is that it’s an escape for me in some ways.

“Because all of these things are stuff that I have bottled up. I don’t know because we don’t talk about these things. They are not things that are discussed.

“The way that I am, on the tennis court, I show some positive things about my personality and I also show the bad things and things I really hate. Tennis allows me to be that child, that has all of these questions and that’s why tennis is important to me.”

The Amazon Prime documentary, Andy Murray: Resurfacing, which will be released on Friday, follows Murray as he recovers from the hip injury that has plagued his career in recent years.

Speaking ahead of its release, Murray revealed he contemplated retirement a matter of weeks before winning the European Open in Antwerp last month.

“Asia was basically where I started to realise I can do this because at the beginning of that trip, literally two or three days before the first tournament in Asia, I was having conversations with my team,” he said. “I was practising and I was like ‘no, I am giving this until the end of the year and if I’m not winning matches and feeling better than I am now, I don’t want to keep going.’”

Following a successful period in Asia, the double-Wimbledon winner closed out the season with victory over Stan Wawrinka in the final in Antwerp.