McCain, 80, is a Republican who lost the 2008 presidential election to Democrat Barack Obama. He is considered a war hero from his service in the Vietnam War.
His office and the Mayo Clinic Hospital in Phoenix, Arizona, provided the medical information about McCain on Wednesday night.
McCain was diagnosed with glioblastoma, an aggressive form of cancer. It forms tumors in the brain and spinal cord, according to the American Brain Tumor Association.
The American Cancer Society estimates that people who develop glioblastoma after the age of 55 have a five-year survival rate of 4 percent.
McCain's Senate office said the senator is in "good spirits" as he continues to recover from surgery at his Arizona home.
Praise for McCain came from leaders of both political parties. Former President Obama tweeted:
"John McCain is an American hero & one of the bravest fighters I've ever known. Cancer doesn't know what it's up against. Give it hell, John."
Republican President Donald Trump, who once questioned whether McCain was really a war hero, also offered best wishes.
"Senator John McCain has always been a fighter. Melania and I send our thoughts and prayers to Senator McCain, Cindy, and their entire family. Get well soon."
Before entering politics, McCain was a Navy fighter pilot. He was imprisoned and tortured by the North Vietnamese for five years after his plane was shot down.
McCain refused the North Vietnamese offers to leave early from a prison known as the "Hanoi Hilton." McCain said he would not leave unless fellow American prisoners of war were also released. When McCain was finally released in 1973, he was badly injured and weakened.
McCain has survived other health issues, including melanoma -- the most dangerous form of skin cancer. He also faced a variety of health problems caused by his five years of imprisonment in Vietnam.
His daughter, Meghan, said her father is demonstrating his usual strength and bravery.
"It won't surprise you to learn that in all this, the one of us who is most confident and calm is my father," she said. "He is the toughestperson I know."
McCain's office said his doctors will decide when he can return to the Senate. A lengthy absence will make it more difficult for the Trump administration and Republican congressional leaders to pass bills.
Republicans had already delayed a vote on eliminating and replacing the health law, known as Obamacare. The delay was announced after McCain had surgery last week to remove a blood clot from behind his left eye.
On Wednesday night, the Mayo Clinic and the Arizona Republican's office announced McCain's diagnosis of a brain tumor.
McCain's doctors said the senator's next treatment may include a combination of chemotherapy and radiation.
Republican Senator Jeff Flake also represents the state of Arizona. He found out about the cancer during a telephone discussion with McCain.
"Only at the end of the conversation, I asked him how he was feeling today, and he said, 'I'm feeling fine, but I might have some chemotherapy in my future,'" Flake said on ABC television. "And that's how I learned of it. So it was almost in passing about his diagnosis."
Flake went on to say that McCain sounded "optimistic."
"He's John McCain -- that's what we expect," Flake said.
Words in This Story
diagnose - v. to recognize a disease or injury by examining someone
tumors - n. a mass of tissue found in or on the body that is made up of abnormal cells
spinal cord - n. the large group of nerves which runs through the center of the spine and carries messages between the brain and the rest of the body
confident - v. having a feeling or belief that you can do something well or succeed at something
toughest - adj. physically and emotionally very strong
chemotherapy - n. the use of chemicals to treat or control a disease such as cancer
conversation - n. a discussion with someone
optimistic - adj. having or showing hope for the future