The cancer was discovered after undergoing treatment for an enlarged prostate, but is not prostate cancer, the palace added in a statement.
The King "remains wholly positive about his treatment and looks forward to returning to full public duty as soon as possible," the Palace continued.
The King is expected to postpone public engagements while undergoing treatment. Other senior royals are likely to take over royal duties in his absence.
The statement said the King had chosen to go public with his diagnosis "to prevent speculation" and to assist public understanding of the condition.
The announcement by Buckingham Palace drew swift reactions from all corners.
UK Prime Minister Rishi Sunak wrote on X, formerly Twitter: "Wishing His Majesty a full and speedy recovery.
I have no doubt he’ll be back to full strength in no time and I know the whole country will be wishing him well."
Meanwhile, the leader of the opposition Labour party, Keir Starmer, wrote on X: "On behalf of the Labour Party, I wish His Majesty all the very best for his recovery.
"We look forward to seeing him back to swift full health."
US President Joe Biden was also among the well-wishers, writing on X that "navigating a cancer diagnosis, treatment, and survivorship takes hope and absolute courage."
"Jill and I join the people of the United Kingdom in praying that His Majesty experiences a swift and full recovery," he added.
The King started receiving treatment for a benign enlarged prostate one week ago. He is said to have been delighted to help raise awareness of the condition.
NHS England, the UK's public health service, said the "enlarged prostate" page on its website received one visit every five seconds on the day his diagnosis was announced, as well as further huge boosts in visits during the following days.