The second-seeded Murray, a two-time Rogers Cup champion, was playing his second match since his Wimbledon victory. The loss ended the Scot's winning streak at 13 matches.
"I looked on this monitor that I lost to him five times, but honestly I just remember the last match we played in Cincinnati," Gulbis said. "It was a really tough match, but it was in 2010. It was a really long time ago. I was a different person, he was a different player."
Top-seeded defending champion Novak Djokovic avoided an upset in the last match, rallying to beat Uzbekistan's Denis Istomin 2-6, 6-4, 6-4. Djokovic will face seventh-seeded Richard Gasquet of France, a 1-6, 6-3, 6-3 winner over ninth-seeded Kei Nishikori of Japan.
Rafael Nadal won his third round match, beating Poland's Jerzy Janowicz 7-6 (6), 6-4.
Nadal, the fourth-seeded Spanish star making his first tournament appearance since losing in the first round at Wimbledon, improved his ATP Tour-leading record to 45-3 -- including 7-0 on hardcourts.
"I had a very good victory today against a very difficult opponent," Nadal said about the 6-foot-8 Janowicz. "I did a few things well during the match, a few things that I need to improve a little bit more. His serve is huge. His forehand and backhand can be very dangerous.
"When he plays with a little bit of regular shots, he will become a very difficult player to beat. If he is able to maintain the right level during whole match he will be a player that will be in the very top positions."
The Rogers Cup winner in 2005 and 2008, Nadal will face Australia's Marinko Matosevic, a 7-6 (7), 6-7 (10), 6-3 winner over France's Benoit Paire.
Canadians Milos Raonic and Vasek Pospisil advanced, the first time two Canadians have reached the quarterfinals in the event since Andrew Sznejder and Grant Connell in 1989.
Raonic, seeded 11th, upset sixth-seeded Juan Martin Del Potro, the Argentine player coming off a tournament victory Sunday in Washington, 7-5, 6-4. Del Potro was upset that Raonic got away with touching the net with his hand on break point in the eighth game of the second set.
"Very upset after the match I lost," Del Portro tweeted. "About the end. .. I think everyone saw what happened."
Raonic said it was too important of a point to call a foul on himself.
"I was fortunate that the line judge didn't see it," he said. "It's a lucky thing for me in my sense, unlucky for him. Something that can go really both ways. It's the exact same thing as having no challenges left and you get a bad line call. It's bad luck. It was hard to be able to take this point on such a big point."
Pospisil beat fifth-seeded Tomas Berdych of the Czech Republic 7-5, 2-6, 7-6 (5) for his first victory over an opponent ranked in the top 10.
"That was the best match in terms of atmosphere at the end that I've ever played," Pospisil said. "That and the doubles in Davis Cup (a win over Italy this year) were pretty even in terms of atmosphere. They were both amazing. But that was definitely the most emotional ending and best match of my career, without a doubt."
On Friday, Pospisil will face Nikolay Davydenko, who downed fellow Russian Alex Bogomolov Jr. 6-4, 6-3.
"If I can keep playing the way I am now, at least I'll give myself an opportunity," Pospisil said.
Raonic will play Gulbis.