These days, most people imagine that when they succumb to the inevitable and utter what must be their "last words", they will have time for little more than a brief, faltering sentence. If they are lucky, it will be shared with a few close family members before being swiftly consigned to the scrapheap of history.

Professor Randy Pausch is not most people, though. In September, the previously unknown computer science expert delivered a remarkable lecture to students at Carnegie Mellon University in Pittsburgh. Thanks to the wonders of technology, the hour-long speech did not disappear into the ether, but went on to be heard by millions. It has since changed lives, touched American politics, and is about to spawn a publishing phenomenon.

At the centre of Pausch's remarkable tale is "The Last Lecture," an old academic conceit whereby teachers are asked to imagine they're near death and must therefore sum up the entire collection of wisdom they wish to pass on to their students in a single lecture. Pausch, a 47-year-old father of three, didn't have to imagine anything when he gave his own "last lecture" on 18 September. He had just been diagnosed with terminal pancreatic cancer.

Download the new Independent Premium app Sharing the full story, not just the headlines

In a little over an hour, to a packed lecture-hall, Pausch delivered a deeply moving speech on the subject of "really achieving your childhood dreams." The optimistic philosophy he espoused, in a lecture punctuated by both laughter and tears, resulted in scenes resembling a real-life version of Dead Poets Society. To Americans who have recently, through the likes of Barack Obama, learnt to love public speaking, it has provided a timely reminder of how life ought to be lived.

The first public mention of Pausch's lecture appeared in The Wall Street Journal, whose columnist Jeff Zaslow heard about it on the grapevine. "I almost didn't go," Zaslow recalls. "I live in Detroit, about 300 miles away, and I ended up driving to save the cost of a flight. It was like watching Babe Ruth hit his last home run, or Michael Jordan hitting his jump shot at the end of the NBA finals. It was electric in that room. I knew it affected everyone that was there. But I could not have foreseen what followed, even in my wildest dreams."

Zaslow decided to write about the lecture in his next column, and put together a five-minute highlights video of it for the Journal's website. And so a monster was created: readers passed the clip to their friends and it became a viral hit, receiving hundreds of thousands of views on YouTube and other platforms in a matter of hours. "It just took off," says Zaslow. "The ABC TV network's Good Morning America show saw it in the Journal and had Randy on the following morning. Immediately after that, a million people logged on to the ABC website just to find out more about him. I've since had thousands of emails from people saying how much it moved them and how it has changed their lives."

Soon, the video of the entire, hour-long talk was available online. More than six million people have watched the life-affirming lecture in full on YouTube. In October, Pausch was invited to appear on The Oprah Winfrey Show, where he gave an edited reprise of his talk to Winfrey's 10 million-strong television audience. Next month, his thoughts will be published in The Last Lecture, a book co-written by Zaslow, for which the US publishers Hyperion forked out a reported $6.7m (about £3.4m) advance after a bidding war.

In a market crammed full of questionable self-help tomes, Pausch's honest and humble life lessons are expected to top bestseller lists in America and have already been translated into 18 languages. "They keep taking the Oprah clip down off YouTube because of copyright infringement," Zaslow says. "But it gets a million views every time before it disappears."

Meanwhile, on 13 March, still alive against the odds, Pausch appeared before a congressional subcommittee on behalf of the Pancreatic Cancer Action Network (Pancan). Chemo and radiation therapy have kept him alive long enough to demand that Congress set aside $170m to find a cure for the disease, but the treatment has led to congestive heart and kidney failure.

It was a harrowing testimony. There's little or no way of preventing pancreatic cancer. Though smoking or poor diet, for instance, can increase the risk of contracting it, little is known of the disease's causes. Only one case in 10 is attributed to hereditary genes. Pausch has never smoked or drunk heavily, and used to exercise every day. When he first developed symptoms, he thought it was hepatitis. "When we got the diagnosis, my wife said, 'Gee, I guess you'd trade for hepatitis,'" Pausch told the subcommittee. "I said, 'Honey, I'd trade for Aids. In a heartbeat.'"

Daily coronavirus briefing No hype, just the advice and analysis you need Enter your email address Continue Continue Please enter an email address Email address is invalid Fill out this field Email address is invalid Email already exists. Log in to update your newsletter preferences Register with your social account or click here to log in I would like to receive morning headlines Monday - Friday plus breaking news alerts by email Update newsletter preferences

Adding grist to Pausch's mill was the fact that, although two-thirds of sufferers are over 70, he's not the only young victim to have brought pancreatic cancer to public attention recently: at the beginning of this month, the actor Patrick Swayze announced that he had been diagnosed with the disease and was undergoing aggressive chemotherapy treatment.

So what of the speech itself? Pausch begins his "last lecture" by introducing the elephant in the room: the CAT scans of his liver, and the 10 or so tumours that are attacking it. He apologises to those who think he should be more depressed and morose. Then he does some press-ups. This is typical of the persona that has made him so popular in his final months.

"He's a showman," says Zaslow, who has become a friend as well as a colleague. "The first time I spoke to him was on the phone the day before the lecture. He was cycling and speaking on his cellphone headset, and I said, 'Do you want to stop and call me from a landline? I don't want you to get in an accident.' He said, 'So I get in an accident. What's the difference?' So I could tell that he had a sense of humour before I even got there."

"I don't know how to not have fun," Pausch tells his audience. "I'm dying and I'm having fun, and I'm going to keep having fun every day I've got left."

Pausch was a founder of CMU's Entertainment Technology Centre and created a pioneering computer science course, Building Virtual Worlds, which he taught there for 10 years. It sounds like the most fun a programmer can have: his students were taught how to turn virtual reality technology into entertainment, in video games and amusement-park rides.

However, his last lecture, which Pausch entitled "Really achieving your childhood dreams", takes as its theme his youthful ambitions: how he achieved them, and how he helped others to achieve theirs. He doesn't discuss spirituality or religion, but speaks with the simple authority of a man who is looking death in the face and assessing what's really important about life. "Never lose the childlike wonder," he advises. "Show gratitude... Don't complain; just work harder... Never give up."

"I think we're hungry for something that's real," Zaslow says. "Celebrity today is so plastic and doesn't resonate with people, but there's something about what Randy had to say that really touched a nerve. He's real; he's just telling it the way it is. Many people have known someone that died, or are dying themselves. All of us want to live and live life to the fullest. He articulated that in a way that captured people's imaginations."

Most of Pausch's successfully realised dreams were gloriously nerdy, like seeing his name in the World Book Encyclopedia, floating in zero gravity and meeting Captain Kirk (or, at least, William Shatner). He also describes how not achieving a dream can be as enriching as achieving one. "Experience is what you get when you didn't get what you wanted," he says, reflecting on the fact that he never made it as a gridiron player. Three weeks after his lecture, however, the Pittsburgh Steelers invited him to take part in a practice session, so fulfilling his dream of joining the National Football League, if only for a day.

The team weren't the only ones to demonstrate such generosity. JJ Abrams, the director of the new Star Trek film, heard about Pausch, learnt that they shared an obsession with the sci-fi series and invited the professor to the Los Angeles set to film a cameo appearance.

One of Pausch's aspirations was to become a Disney "imagineer", one of the elite who dream up, design and manufacture the magic in Disney's magic kingdom. He became a part-time member of the team that created Disneyworld's Magic Carpet Ride (based on the movie Aladdin) and Pirates of the Caribbean. Disney has given Pausch another boost in his final months – the corporation owns Hyperion, the publisher that paid a multi-million advance on Pausch's book.

Pausch's positive outlook seems to have come from his family. One of his lecture slides shows his mother go-karting on her 70th birthday; another shows his father riding a roller-coaster on his 80th. The most touching moment of the lecture comes when Pausch announces that the previous day had been his wife Jai's birthday. The audience of 500 sing "Happy Birthday" as a cake is wheeled out and Jai tearfully blows out the candles.

"It was such an emotional moment," Zaslow says. "I've seen it 100 times now and it doesn't move me so much, but to be there on the day was incredible – it was a remarkable act of love. Jai told me later that she whispered in his ear, 'Please don't die.' It sounds like Hollywood dialogue." That piece of Hollywood dialogue is inaudible on video, but will make it into the published version. The book had to be completed in record time, for obvious reasons.

Zaslow visited Pausch three times, but mostly they talked on the phone, one hour a day for 53 days straight; Pausch pounding the asphalt on his bike, Zaslow tapping at a keyboard on the other end of the line. Until very recently, Pausch was in great physical shape: cycling every day, running somewhat faster than the majority of his countrymen and, of course, interrupting his lectures to do a few quick press-ups.

But now, Pausch has stopped the palliative chemotherapy intended to extend his short lifespan for as long as possible. He spends many days confined to bed. "He's not riding his bike any more," Zaslow admits. "The appearance before Congress took a lot out of him. He almost died in a car accident that day – their limo driver hit a truck. He joked about that, too."

Pancreatic cancer is the fourth-deadliest cancer, killing 75 per cent of sufferers within a year. Only 4 per cent make it to their fifth year. According to Pancan, more than 37,000 people are diagnosed with the disease, and more than 33,000 die from it, each year in the US. In the UK, the number diagnosed each year is about 7,400.

Pancan hopes the attention being paid to pancreatic cancer will at least result in more effective early detection. At the moment, less than 2 per cent of America's National Cancer Institute budget is allocated to pancreatic cancer research. Pausch's fame may help to change that. He has appeared in TV spots for Pancan, explaining the state of research funding. "I'm a professor," he says in the advert. "I know that people in research labs can do miraculous things if they're given the resources."

Pausch talks about his students, friends and colleagues with great warmth and humour. Their tributes show that the professor is much loved. Pausch ends his last lecture with a couple of confessions, however. First, the lecture isn't really "about how to achieve your dreams. It's about how to live your life. If you lead your life the right way, the karma will take care of itself; the dreams will come to you." Second, the life lessons it contains are really meant for his three young children as they grow up.

In the advertising material for his book, he admits that "the lecture was only for three people – my kids." As for the book: "It's only the first three copies I really care about." The other people he has touched are just a wonderful side-effect. "Judging by the emails I get and the comments on the thousands of blogs devoted to it," Zaslow says, "young people love him, old people love him, academics love him, parents love him, cancer patients love him." His passing may be private, but Randy Pausch will be mourned by millions.

The Last Lecture by Randy Pausch and Jeffrey Zaslow will be published in the UK by Hodder & Stoughton on 17th April, £12.99

Achieving your childhood dreams – by Randy Pausch

* "Really Achieving Your Childhood Dreams"

* Randy Pausch's "final" lecture was given on 18 September 2007, as part of a series at Carnegie Mellon University. A full transcript is carried at www.randypausch.com. Here are some highlights.

* "It's wonderful to be here. What they didn't tell you is that this lecture series used to be called 'The Last Lecture'. If you had one last lecture to give before you died, what would it be? I thought, damn, I finally nailed the venue and they renamed it."

* "We cannot change the cards we are dealt, just how we play the hand. If I don't seem as depressed as I should be, sorry to disappoint you. I assure you I am not in denial. It's not like I'm not aware of what's going on... The other thing is that I am in phenomenally good health right now. I mean, it's the greatest thing of cognitive dissonance you will ever see: the fact that I am in really good shape. In fact, I am in better shape than most of you. [Pausch starts doing push-ups.] So anybody who wants to cry or pity me can get down and do a few of those."

* "How do you get people to help you? By telling the truth. Being earnest. I'll take an earnest person over a hip person every day, because hip is short-term."

* "Apologise when you screw up and focus on other people, not on yourself. How do I make a concrete example of that? See, yesterday was my wife's birthday. If there was ever a time I might be entitled to have the focus on me, it might be the last lecture. But no, I feel very badly that my wife didn't really get a proper birthday, and I thought it would be very nice if 500 people... [a birthday cake is wheeled on to the stage]."

* "Remember, brick walls let us show our dedication. They are there to separate us from the people who don't really want to achieve their dreams. Don't bail. The best of the gold's at the bottom of barrels of crap."

* "Show gratitude. When I got tenure I took all of my research team down to Disney World for a week. And one of the other professors said, 'How can you do that?' I said: 'These people just busted their ass and got me the best job in the world for life. How could I not do that?'"

* "Don't complain. Just work harder [shows slide of Jackie Robinson, the first black major league baseball player]. It was in his contract not to complain, even when fans spit on him."

* "Work hard. I got tenure a year early. Junior faculty members used to say to me, 'What's your secret?' I said, 'It's pretty simple: call me any Friday night in my office at ten o'clock and I'll tell you.'"

* "Find the best in everybody. You might have to wait a long time, but people will show you their good side. Just keep waiting, it will come out. And be prepared. Luck is truly where preparation meets opportunity."

Pancreatic cancer: the victims that rocked the world

Luciano Pavarotti

Operatic superstar Pavarotti died in September last year after a year-long battle with pancreatic cancer. Despite successful surgery to remove tumours in 2006, his condition worsened and he was forced to call off concerts. He was 71 when he died. Two-thirds of pancreatic cancer sufferers are aged 70 or over.

Magnus Magnusson

The much-loved Mastermind host died in January 2007, just four months after being diagnosed with cancer. He was 77. His four surviving children said he had taught them both how to live, and how to die. "He did both," they said, "with infinite grace."

Syd Barrett

Roger Keith Barrett – known as Syd – was the iconoclastic former frontman for Pink Floyd. A recluse, he died of pancreatic cancer in 2006, aged 60. The original acid casualty was supposedly the subject of his bandmates' anthem "Shine on You Crazy Diamond".

Bill Hicks

Bill Hicks, an incendiary American comedian, was diagnosed with pancreatic cancer in 1993, aged just 31. He continued to perform while undergoing chemotherapy, even using his condition for material. One of his more famous jokes concerned the actor Yul Brynner, who, like Hicks, blamed his own death on prodigious smoking. Hicks died in February 1994.

Dizzy Gillespie

Jazz trumpeter John Birks 'Dizzy' Gillespie died of the disease in 1993, aged 75, in Englewood, New Jersey. Englewood Hospital established the Dizzy Gillespie Cancer Institute and Memorial Fund in his memory.

Rene Magritte

Magritte, the Belgian surrealist known for his witty paintings of pipes, apples and bowler hats, died of pancreatic cancer in Brussels in 1967. Though his painting was famously "not a pipe", Magritte was a smoker.

Miles Kington

The journalist and satirist Miles Kington, a dearly missed daily contributor to The Independent, died in January aged 67, after a short battle with pancreatic cancer, soon after filing his final column.

Patrick Swayze

The Hollywood star best known for Dirty Dancing and Ghost announced that he had been diagnosed with pancreatic cancer earlier this month. He is now undergoing chemotherapy. Swayze, 55, plans to continue working despite his condition.