The Frenchman got the better of his opponent (4)6-7 7-6(4) 2-6 7-6(11-9) 7-5 in almost five hours.
The duo went toe-to-toe in the first set in which Raonic blew a set-point opportunity with a wild forehand and then made two successive double faults to allow his opponent to come back and level it at 5-5.
The Canadian eventually won the opening set, but lost the second in another tie-breaker. However, the world number 11 bounced back in the third to claim it 6-2 with ease, Gasquet hitting six unforced errors in the process.
The fourth set was close like the first two and was won in a long tie-breaker by Gasquet, with Raonic missing a backhand passing shot on match point at 8-7.
The epic battle between the two players continued in the fifth set which Gasquet won 7-5 to set up a meeting with David Ferrer for a place in the semi-finals.