Buckingham Palace said: "It is with deep sorrow that Her Majesty The Queen has announced the death of her beloved husband, His Royal Highness The Prince Philip, Duke of Edinburgh.
"His Royal Highness passed away peacefully this morning at Windsor Castle."
UK Prime Minister Boris Johnson said he "inspired the lives of countless young people".
Speaking at Downing Street, Johnson added: "He helped to steer the Royal Family and the monarchy so that it remains an institution indisputably vital to the balance and happiness of our national life."
The duke had suffered failing health in recent years, and retired from royal duties in 2017.
On March 16 he had been released from London's King Edward VII hospital, after being admitted a month before as a "precautionary measure".
A statement from Buckingham Palace at the time of his admission said he had been sent to hospital on the advice of his doctor after feeling unwell.
A week later the Palace said he was battling an "infection" and would be staying in hospital.
However the royal family continued to give an upbeat assessment of his health, with his youngest son Prince Edward saying he was "a lot better" and was "looking forward to getting out".
On March 1, Prince Philip was transferred to St Bartholomew's hospital, also in London, where tests were carried out on a pre-existing heart condition. A procedure for that condition was successfully carried out on March 4.
"His Royal Highness will remain in hospital for treatment, rest and recuperation for a number of days," the palace said afterwards. He was later sent back to Edward VII to recover.
Prince Philip was previously admitted to King Edward VII just before Christmas in 2019 for treatment for a pre-existing condition, and remained there for several days.
The prince, who would have turned 100 in June, retired from public life in August 2017 but occasionally made appearances at royal engagements.
Britain's Princess Eugenie and her husband Jack Brooksbank paid tribute to her grandfather by naming their baby boy August Philip Hawke Brooksbank.