In a short message posted on the official royal family Twitter account the Queen said she and the Duke of Edinburgh were saddened to learn of his death.
The death of President Magufuli, aged 61 and a prominent Covid-19 sceptic in Africa was announced on Wednesday by Vice President Samia Suluhu Hassan, who said the president died of heart failure.
“Our beloved president passed on at 6pm this evening,” said Ms Suluhu on national television.
She said that Mr Magufuli died at a hospital in Dar es Salaam, the Indian Ocean port that is Tanzania’s largest city.
Although the vice president said the cause of Mr Magufuli’s death was heart failure, opposition politicians had earlier alleged that he was sick from Covid-19.
The Queen said in her message: “Prince Philip and I were saddened to learn of the death of President John Magufuli. I wish to convey my condolences to his loved ones and my deepest sympathy to the people of Tanzania.”
Ms Hassan has now been sworn in as Mr Magufuli’s successor as president.
The Prince of Wales said on social media that he and the Duchess of Cornwall were saddened by Mr Magufuli’s death.
In a statement posted on Twitter he said: “My wife and I were saddened to hear the news of the death of John Pombe Magufuli, President of the United Republic of Tanzania.
“We particularly wanted to convey our condolences to President Magufuli’s family and loved ones.
“I can only assure you that our thoughts and prayers are with the people of Tanzania at this most difficult time.”
The Duke of Cambridge also tweeted his condolences and said: “I send my condolences to the people of Tanzania following the death of President Magufuli.
“I hugely enjoyed my visit to Tanzania in 2018, when I was warmly welcomed by the President.
“My thoughts are with his family and the people of Tanzania at this difficult time. W.”