“Cancer doesn’t know what it’s up against,” Mr. Obama tweeted. “Give it hell, John.”

The diagnosis shook the Senate, where Mr. McCain is a popular figure despite his occasionally heated disputes with colleagues in both parties. His illness had implications this week for the health care debate, causing Senator Mitch McConnell, Republican of Kentucky and the majority leader, to postpone a floor fight until Mr. McCain returned to Washington.

On Wednesday night, about a dozen lawmakers gathered in the Dirksen Senate Office Building to explore a health care compromise asked Senator James Lankford, an Oklahoma Republican who is a Baptist minister, to lead them in prayer for their colleague.

“It was very emotional,” said Senator John Hoeven, Republican of North Dakota, who was present. He said finding a solution to the health care impasse was “more challenging without him.”

Mr. McConnell called Mr. McCain a hero to both Senate Republicans and the nation at large.

“He has never shied from a fight, and I know that he will face this challenge with the same extraordinary courage that has characterized his life,” Mr. McConnell said Wednesday night. “We all look forward to seeing this American hero again soon.”

Mr. McCain endured grueling rehabilitation from his time in the prison camp but later led the effort to reconcile with Hanoi in a striking gesture of forgiveness. After quickly becoming prominent as a House member in his first election in 1982, Mr. McCain won the Senate seat given up by the Arizona icon Barry Goldwater in 1986. He became a fixture in the Senate, where he denounced the corrosive effects of big money in political campaigns and was a central player in congressional debates on military policy, immigration and health care.

Wednesday’s disclosure suggested that Mr. McCain’s condition was more serious than initially believed, although the statement said that “he is recovering from his surgery ‘amazingly well,’” according to his doctors, “and his underlying health is excellent.”