After he was paralyzed by polio at age 6, Paul Alexander was confined for much of his life to a yellow iron lung that kept him alive. He was not expected to survive after that diagnosis, and even when he beat those odds, his life was mostly constrained by a machine in which he could not move.

But the toll of living in an iron lung with polio did not stop Mr. Alexander from going to college, getting a law degree and practicing law for more than 30 years. As a boy, he taught himself to breathe for minutes and later hours at a time, but he had to use the machine every day of his life.

He died on Monday at 78, according to a statement by his brother, Philip Alexander, on social media.

He was one of the last few people in the United States living inside an iron lung, which works by rhythmically changing air pressure in the chamber to force air in and out of the lungs. And in the final weeks of his life, he drew a following on TikTok by sharing what it had been like to live so long with the help of an antiquated machine.

It was unclear what caused Mr. Alexander’s death. He had been briefly hospitalized with the coronavirus in February, according to his TikTok account. After he returned home, Mr. Alexander struggled with eating and hydrating as he recovered from the virus, which attacks the lungs and can be especially dangerous to people who are older and have breathing problems.

Mr. Alexander contracted polio in 1952, according to his book, “Three Minutes for a Dog: My Life in an Iron Lung.” He was quickly paralyzed, and doctors at Parkland Hospital in Dallas put him in an iron lung so that he could breathe.

“One day I opened my eyes from a deep sleep and looked around for something, anything, familiar,” Mr. Alexander said in his book, which he wrote by putting a pen or pencil in his mouth. “Everywhere I looked was all very strange. Little did I know that each new day my life was unavoidably set on a path that would become unimaginably strange and more challenging.”

While innovations in science and technology led to portable ventilators for people with respiratory problems, Mr. Alexander’s chest muscles were too damaged to use any other machine, and he was reliant on the iron lung for much of his life, according to The Dallas Morning News, which profiled him in 2018.

When he was inside the machine, Mr. Alexander needed the help of others for basic tasks such as eating and drinking. For much of his life, that help came from his caregiver, Kathy Gaines, Mr. Alexander wrote in his book.

Mr. Alexander launched his TikTok account in January, and, with help from others, he began creating videos about his life. Some addressed broader parts of his life, like how he practiced law from the iron lung.

In other videos, he took questions from his more than 330,000 followers, about more mundane, yet interesting, aspects of his daily life, like how he was able to relieve himself. (A caregiver had to unlock the iron lung, and he would use a urinal or bed pan.)

In one video, Mr. Alexander detailed the emotional and mental challenges of living inside an iron lung.

“It’s lonely,” he said as the machine can be heard humming in the background. “Sometimes it’s desperate because I can’t touch someone, my hands don’t move, and no one touches me except in rare occasions, which I cherish.”

Mr. Alexander said in the video that over the years, he had received emails and letters from people who were struggling with anxiety and depression, and offered some advice.

“Life is such an extraordinary thing,” he said. “Just hold on. It’s going to get better.”

Paul Richard Alexander was born on Jan. 30, 1946, in Dallas to Gus Nicholas Alexander and Doris Marie Emmett. After playing outside on a summer day in 1952, he came home with a 102-degree fever, a headache and stiff neck, his mother wrote in the foreword to his book.

“I had every reason to be terror-stricken, and I was,” she wrote. “Polio, the dreaded disease for every parent, was stalking through our city like a big black monster, crippling and killing wherever he went. Here was Paul with every symptom.”

Mr. Alexander spent several months in the hospital, where he was close to dying on several occasions.

“Finally, one day the doctor called us in and told us Paul could not live much longer and if we wanted him at home with us when he died, we could take him,” his mother wrote.

His journey home with the iron lung made workers at the hospital “tense,” and it involved a truck with a generator in the bed to keep the machine working, his mother wrote.

When he was 8, Mr. Alexander learned to breathe on his own for up to three minutes by gulping in air “like a fish” and swallowing it into his lungs, he told The Dallas Morning News.

Mr. Alexander told the newspaper that he was motivated to learn to breathe by a caregiver who offered him a puppy if he tried to learn to breathe on his own. He got his puppy, and it later became the inspiration for the title of his book, “Three Minutes for a Dog.”

Mr. Alexander was one of the first students to be home-schooled through the Dallas Independent School District, and, in 1967, he graduated second in his class from W.W. Samuell High, according to The Dallas Morning News.

“The only reason I didn’t get first,” he told the newspaper, “is because I couldn’t do the biology lab.”

After high school, Mr. Alexander attended Southern Methodist University in Dallas before he transferred to the University of Texas at Austin to study economics and finance, according to the “Alcalde,” the alumni magazine of the University of Texas.

By learning to breathe on his own, Mr. Alexander was able to live outside the iron lung for hours at a time, and students from his dorm would take him to class in wheelchair, according to the Alcalde. He then attended law school at the University of Texas and earned his law degree in 1984.

Mr. Alexander is survived by his brother, his nephew Benjamin Alexander, his niece Jennifer Dodson and his sister-in-law Rafaela Alexander, according to Dignity Memorial. His funeral service is scheduled for March 20 at the Grove Hill Funeral Home & Memorial Park in Dallas.

Before his death, in a video posted on TikTok on Jan. 31, Mr. Alexander said that he had been surprised and moved by the response to his videos.

“It makes me feel like there’s somebody that really cares about me,” he said. “I wish I could hug every one of you.”