Nadal staged a furious rally in the third after trailing 5-2. He won three straight games, including a break of Dolgopolov, to tie it up. Both players held serve to send the match into the tiebreaker.
They slugged it out from the baseline accompanied by a noisy soundtrack, with fans yelling and cheering. Los Angeles Lakers star Pau Gasol watched nervously from Nadal's box. Nadal led 4-2 before Dolgopolov won three straight points to take a 5-4 lead. The Ukrainian hit two forehand winners and came up with a big service winner.
"I had enough breaks to win the match, but I didn't play enough well from the baseline then to be solid with my serve," Nadal said. "I didn't go for the points. I played with too many mistakes."
Nadal evened it at 5-all, but he hit the ball long to set up match point. Dolgopolov served what he thought was an ace, but it was called out. He challenged the call and it showed the ball barely missed tagging the T. Dolgopolov put his second serve into play and produced a cross-court forehand that Nadal couldn't return.
"It's a moment for the people to be proud a little bit for someone from their country," Dolgopolov said, referring to the political upheaval going on between Ukraine and Russia. "It's good to make some results and make the people forget a little bit and have some happy moments in the news."
Dolgopolov had more errors (49) than winners (36).
Last month, Nadal defeated Dolgopolov to win the Rio de Janeiro title. The Ukrainian has risen quickly in the ATP Tour rankings, going from No. 57 to 31st after a strong February, posting three wins against top-20 players in Rio and making the semifinals in Acapulco.
The fifth-seeded Scotsman had his hands full playing for the first time against Vesely, who at age 20 is the youngest member of the top 100 of the ATP Tour rankings and was competing in his first Masters 1000 event.
Murray had 47 of the 99 unforced errors during the nearly three-hour match in the 80-plus-degree heat of the Southern California desert. The third set featured six service breaks, with Murray taking the last two.
"It was that sort of match where at no stage did either of us play well at the same time," Murray said. "There wasn't one period where I thought the level of tennis from both of us was high at the same time. That can create a lot of breaks and a lot of sort of back and forth swings in the match."
Vesely staved off two match points with a pair of winners. But the Czech double-faulted to set up Murray's third match point and he netted a forehand volley to end his upset bid.
"Until 4-2 in both sets, second and third, I was playing good without any mistakes," Vesely said. "But then I always got a little bit tight. That was maybe the one thing that was painful then in the end."
Federer has regained some of the momentum that eluded him last year, when he won just one title. Last week, he won the tournament in Dubai with victories against Novak Djokovic and Tomas Berdych. At the Australian Open, the former world No. 1 earned wins over Jo-Wilfried Tsonga and Murray before losing to Nadal.
"I feel different this year," Federer said. "Now I feel like I'm in a good place. Zen on the court. Even if I won 6 and 6 today, I just feel like I was calm. Those are the moments where you feel there is confidence around somewhere."
Information from The Associated Press was used in this report.