Federer prevailed 6-3 3-6 7-6 (9-7) to book his place in the last eight at Halle, but he was far from his fluent best against the destructive Frenchman.
Paire produced 59 winners and 44 unforced errors to contribute to another unpredictable performance as Federer found a way to progress.
The Swiss will face Matthew Ebden in the quarter-finals after he dropped the first set before losing just three more games in defeating Philipp Kohlschreiber 4-6 6-1 6-2.
Federer – who has to win the title in Halle to keep his No 1 ranking – saved two match points to register his 18th consecutive win on the grass.
He is still on track to secure title No 10 in 2018 but, after Paire looked like he would let his frustrations get the better of him in losing the first set, he roared back with two breaks to eventually claim the second.
Federer struggled to find his rhythm throughout due to his opponent’s disruptive style of play, but after winning four straight points in the final tiebreak, Paire’s forehand deteriorated at the vital moment as the Swiss survived by the skin of his teeth.
Elsewhere, Borna Coric overcame the Georgian Nikoloz Basilashvili 6-4 6-2 to set up a quarter-final against Andreas Seppi.
Seppi, who was beaten by Federer in the final at Halle three years ago, came out on top in his clash with German Florian Mayer 6-2 6-4.
We are in Germany for the Gerry Weber Open in Halle, live on Sky Sports Arena all this week.
Never miss the big kick-off or have to deal with interrupted games or low quality streams with a NOW TV Sky Sports Pass this summer. You’ll get exclusive coverage of the 147th Open from Carnoustie, The Ryder Cup. England’s summer Rugby tour to South Africa, ATP Tour, World Darts Matchplay, and loads more starting from just £7.99. No contract.