World number three Roger Federer dropped his first set since June on Thursday but recovered to dispatch Spaniard David Ferrer 4-6 6-4 6-2 at their last 16 meeting in the Rogers Cup.
Federer was sloppy from the start on centre court, sending routine forehands wide and providing the underdog Ferrer with early break opportunities in the ATP 1000 event in Montreal.
Ferrer capitalised by winning the first set to end Federer's streak of 32 consecutive sets won, a record that dates back to his defeat by Tommy Haas at the Stuttgart Open on June 14.
Frustration boiled over for the Swiss in the second set after he misfired with an overhead smash.
Federer, who turned 36 this week, responded by hitting a ball into the stands, earning a scolding but no official ball abuse call from the umpire.
The outburst appeared to steady the Swiss, whose serve and overall accuracy improved as the two-hour match progressed.
Ferrer has now lost all of his 17 contests against Federer, who is vying to take the world number one spot from injured Briton Andy Murray.
Next up for Federer is a quarter-final against 12th-seeded Spaniard Roberto Bautista Agut, who defeated Frenchman Gael Monfils in a marathon match 4-6 7-6(5) 7-6(2) on Thursday.