* World number one beaten by Bulgarian in second round
* Defending champion Federer eases past Stepanek
* Murray comes through stiff test against Mayer (Adds quotes, details)
By Iain Rogers
MADRID, May 7 (Reuters) - Novak Djokovic was dumped out of the Madrid Open in the second round on Tuesday when he went over on his ankle and incurred the wrath of the locals on the way to a shock 7-6 6-7 6-3 reverse to Bulgarian Grigor Dimitrov.
The world number one, who had a bye in the opening round, was already a break down to the unseeded 21-year-old in the second set when he twisted the same ankle he hurt playing for Serbia in the Davis Cup last month.
After a lengthy medical timeout, he broke back and saved a match point on the way to taking the tiebreak 10-8 to force a deciding set.
He immediately lost his serve for a third time, however, and world number 28 Dimitrov battled through cramp to seal by far the biggest win of his career, ending Djokovic's bid for a fourth title of 2013.
Djokovic said his preparation for the claycourt event had not been ideal as he had not touched a racket for 12 days following his victory against Rafa Nadal in the final of last month's Monte Carlo Masters.
"Up until Saturday I didn't know whether I would come or not because of the ankle," Djokovic said.
"But I am not trying to find an excuse, he was the better player and I congratulate him," added the 25-year-old, who beat Dimitrov in their previous two meetings.
"Nothing really happened when I twisted my ankle because I had good protection so that's the only positive from this. That I didn't injure my ankle worse before Rome and Paris."
Dimitrov, who looked close to tears as he embraced his coaching team at the side of the court, afterwards seemed underwhelmed by the victory, noting that it was "just the second round".
"It's a great win for me. Good day at the office. I know it's a big thing, of course," he told reporters.
"But you got to stay on the ground. Hopefully you're going to face these guys for years. It's just a match. You never know how it's going to be next time."
He said he had not been expecting the crowd to get behind him so completely -- Djokovic annoyed the locals by questioning several line calls -- and the atmosphere had reminded him of a raucous Davis Cup tie.
"I guess tonight was also one of these nights that things are going your way and they're there with you," he said. "You know, the whole fight in general, the three sets, I mean, it was a lot of fun, a lot of entertainment for everyone."
While Djokovic suffered, second seed and defending champion Roger Federer looked as sharp as ever in his first outing after a two-month layoff as he eased past Radek Stepanek 6-3 6-3.
Andy Murray, the third seed, also played earlier on Tuesday and came through a testing encounter against German Florian Mayer 7-6 7-6.
Federer chose an eye-catching mint-green shirt for his first match since losing to Nadal at the Indian Wells Masters in March.
Moving gracefully over the red dust on centre court, the 31-year-old set up a third-round clash against Japanese 14th seed Kei Nishikori or unseeded Serbian Viktor Troicki.
Stepanek, 34, produced a late rally to break the Federer serve in the eighth game of the second set but was broken himself the next game when he sliced a forehand wide.
"I didn't think I played incredible, but that's not what I was expecting myself to do here, but I didn't play bad either," said Federer.
"Overall, I'm very happy, because he has caused me difficulties in the past," added the world number two.
"Today that wasn't the case and I thought I was pretty much in control."
Murray was satisfied with his performance against unseeded Mayer but said his first outing at altitude -- Madrid is around 600 metres above sea level -- had left him short of breath, especially because of a recent illness.
The first-set tiebreak, when Murray saved five set points before coming through 13-11, had been particularly taxing, the Scot said.
"I felt like I hit the ball very well today, very few mis-hits, I just didn't return so well. That was the only thing I would have liked to have done better," he told reporters.
"I was struggling -- I think both of us were -- at the end of the first set. There were so many long points."
Murray, who won the Madrid title in 2008 when it was played on indoor hard courts, will next play the man he beat in the final that year, Gilles Simon.