The governor had been missing meetings since returning from a trade mission to Asia nearly two weeks ago, prompting The Washington Post to report over the weekend that he had been feeling ill. But addressing reporters here on Monday, he said, “I still feel good, I’ve got energy, other than I don’t have much of an appetite. I’m not tired and I’m not in terrible pain.”

Mr. Hogan’s announcement shocked elected officials here and in Washington, and politicians of both parties seemed to rally around him. Senator Barbara A. Mikulski, the Maryland Democrat who plans to retire in January, said she was “stunned and saddened” when Lt. Gov. Boyd Rutherford called her, a few minutes before the governor’s appearance, to share the news.

State Senator Jamie Raskin, the Democratic whip and a cancer survivor who managed a bill to make same-sex marriage legal in Maryland while undergoing his own chemotherapy treatment, praised Mr. Hogan for discussing his diagnosis “in such a detailed and lucid way.”

“I was shell-shocked to hear about the governor,” Mr. Raskin added, “and I feel terrible for him.”

During his brief time as governor, Mr. Hogan has confronted race riots in Baltimore as well as resistance from the Democratic-controlled Legislature on a range of policy matters. His announcement comes at a tumultuous time in Maryland politics, with a contested primary campaign to succeed Senator Mikulski, and Mr. Hogan’s predecessor as governor, Martin O’Malley, seeking the Democratic nomination for president.

Mr. Hogan said Monday that he had discovered the first evidence of the cancer himself, days before leaving for Asia, when he felt a “big lump in my neck” while shaving. He saw his doctor after he returned, he said, and went for a round of tests — with each result sounding worse than the one before.