The world number two was beaten 6-4 6-3 in his first tournament since winning Wimbledon, with Gulbis next facing either Juan Martin Del Potro or Milos Raonic in the quarter-finals.
Murray had Gulbis at 15-40 in the seventh game but the Latvian, who is ranked number 38 in the world, played some great tennis to hold on to his serve and take a 4-3 lead.
The first set continued on serve until Murray's service game let him down and Gulbis found himself with three set points.
The 24-year-old fired the first into the net but made no mistake with the next point as he changed direction on the return of the Scot's second serve to claim the first set.
Gulbis broke Murray's serve again early in the second set to take a 3-1 lead. Murray was on the back foot and despite his best efforts to keep his opponent at bay, he was unable to stop the powerful Latvian from claiming the advantage.
However, Murray hit back immediately with his first break of the match to move back to 3-2, with the second set continuing on serve until Gulbis struck again to claim a 5-3 lead, leaving him to serve for victory.
The first point went to Murray as Gulbis found the net but an ace levelled things up at 15-15 before the Latvian kept his composure to beat Murray down the line.
The Scot took the game back to 30-30 before Gulbis edged ahead, with an ace the decisive blow to claim a straight-sets win over the Wimbledon champion.
Gulbis admitted he had managed to beat Murray despite not playing his best tennis.
"The thing that pleased me the most was that I won," Gulbis told Sky Sports 3.
"I struggled in the first set from the baseline but got more confident and took my chances.
"I didn't blink when serving out for the match but I didn't play my best tennis. I hope I will be even better tomorrow.
"I am excited because I have been ranked 150 coming into this year. I have been struggling and been up and down and I'm going slowly and surely getting back to where I belong.
"With one or two big wins, you're there in the top 10."