The 19-year-old Californian Nakashima, ranked 115th in the world, prevailed 5-7 6-3 7-6 (7-4) over world number 22 Raonic in their first meeting.
The big-serving Canadian had 10 double faults to go with his 27 aces, while Nakashima did not commit one double fault and managed 13 aces.
It was the latest in a string of recent wins over established players for Nakashima, who stunned Sam Querrey and John Isner last week at Los Cabos before falling to Cameron Norrie in the final.
Nakashima next faces Australia's Jordan Thompson, who beat Peter Gojowczyk of Germany 7-6 (8-6) 6-4 to reach the quarter-finals.
In the other half of the draw, fifth seed Taylor Fritz rallied to defeat fellow American Steve Johnson 6-7 (5-7) 6-4 6-1 in a rematch of a quarter-final at Los Cabos, also won by Fritz.
Fritz will face countryman Reilly Opelka, who outlasted Bjorn Fratangelo 7-6 (7-3) 7-6 (7-4). The 6-foot-11 Opelka pounded 25 aces to just three double faults, winning 84 per cent of his service points.