Murray, three times a semi-finalist, wore down France's world number 164 Mathias Bourgue, who had never won a tour-level match before this week, 6-2, 2-6, 4-6, 6-2, 6-3 and goes on to face 37-year-old Ivo Karlovic for a place in the last 16.
After coming back from two sets to love down to beat Radek Stepanek, also 37, in the first round in a tie played over two days, the British star had looked down and out once again today.
But once they were squandered, the Frenchman's challenge quickly wilted as the physically stronger Murray raced away with 12 of the last 15 games.
"He was excellent today. He dictated the points and made me run. He's going to have a fantastic future," said Murray after escaping what would have been his worst loss at the majors since a first round exit at the 2008 Australian Open.
More From This Section
"At the end of the third set, I just thought 'what happened?'. I was 6-2, 2-0 ahead. He was then unbelievable and I found it hard just to win points.
As an indication of his struggles, Wednesday was the first time snce the US Open in 2005 that Murray had played two successive five-set matches at the Slams.
Karlovic, the 27th seed, defeated Australian wildcard Jordan Thompson 6-7 (2/7), 6-3, 7-6 (7/3), 6-7 (4/7), 12-10 in a four and a half hour marathon, unleashing 41 aces and 102 winners.
Karlovic is the oldest man in the French Open third round since 38-year-old Jimmy Connors in 1991.
Defending champion and third seed Stan Wawrinka defeated New York-born Taro Daniel of Japan 7-6 (9/7), 6-3, 6-4 and goes on to face France's Jeremy Chardy.
Japan's fifth seed Kei Nishikori, a quarter-finalist in 2015, coasted into the last 32 with a 6-3, 6-3, 6-3 victory over Russia's Andrey Kuznetsov.
Nishikori, the 2014 US Open runner-up, goes on to face former world number seven Fernando Verdasco of Spain.
Kyrgios will now meet French ninth seed Richard Gasquet
who defeated fellow former boys champion Bjorn Fratangelo of the United States 6-1, 7-6 (7/3), 6-3.
In the women's event, Spanish fourth seed Garbine Muguruza defeated French wildcard Myrtille Georges 6-2, 6-0 and next tackles Belgium's Yanina Wickmayer.
Sixth seed Simona Halep, the losing finalist to Maria Sharapova in 2014, came back from 4-1 down in the first set to beat Zarina Diyas of Kazakhstan 7-6 (7/5), 6-2.
Halep, 24, will next face Japan's Naomi Osaka, the world 101 who has reached the third round at a major for the second successive time having also enjoyed a run to the last 32 in Australia.
Petra Kvitova, the 10th seed, saw off Taiwan's Su-Wei Hsieh 6-4, 6-1 in a much more comfortable outing than her opener against Danka Kovinic where she had been just two points away from defeat.
Kvitova, a semi-finalist in 2012, next faces Shelby Rogers of the United States.
Russian 13th seed Svetlana Kuznetsova, the 2009 champion, was too strong for Britain's Heather Watson winning 6-1, 6-3.
Later today, Canadian eighth seed Milos Raonic takes on France's Adrian Mannarino.
Women's second seed Agnieszka Radwanska, a quarter-finalist in 2013, has a tricky assignment against Frenchwoman Caroline Garcia who won the Strasbourg title at the weekend.