Speaking of perilous odds, the chances of a film like “50/50” turning out to be anything better than awful were slim. It is a comedy about a young man stricken with cancer, first of all, and it costars Seth Rogen, not an actor known for his gentle touch, as the guy’s best friend. You could play it as a farce and go for the dark humor — but no, “50/50” keeps it realistic. How do you get laughs without being insensitive? How do you convey sensitivity without being mawkish? How do you bring an audience to laughter and tears without one or the other (or both) feeling forced? The task is so overwhelming that you’d be inclined to give up.

But then, miracle of miracles, “50/50” succeeds on every level. Written by Will Reiser, a cancer survivor and a friend of Rogen’s, the hilarious and poignant screenplay rings with authenticity as it addresses what happens when someone young and healthy contracts the Big C. People don’t react the same way they do when the patient is elderly, nor does the patient himself react the same way. It makes a certain amount of sense for a person who has lived a long, full life to deteriorate — sad, of course, but an inevitable part of mortality. It’s also far more common, so there are established methods of dealing with it. There’s no such logic when it’s a young person who gets sick. Young people, unaccustomed to pondering such weighty matters at this point in their lives, are far less prepared. And society in general doesn’t know what to do with a dying person who’s barely an adult.

These are all good reasons for a movie like “50/50” not to have existed before. I’m hesitant to say it’s completely unique, but if there have previously been any uproarious-yet-grounded comedies about cancer patients in their 20s, I don’t know what they are. There isn’t a “genre” tag for that on IMDb. At any rate, whether it’s a first or not, “50/50” is a wonderful, cathartic pleasure.

Joseph Gordon-Levitt stars as Adam, a 27-year-old Seattle man who learns early in the film that he has a malignant tumor on his spine. Our introduction to Adam tells us a lot about him: even though there’s no traffic in sight, he’s waiting for the “walk” sign to cross the street. Cautious, polite, and unassuming, he’s not even aware that his brittle girlfriend, Rachael (Bryce Dallas Howard), is using him for a doormat until his best friend points it out.

That best friend is Kyle, played by Seth Rogen as the sort of lovable, horny slacker that Seth Rogen usually plays. But Rogen rises to the occasion just like Kyle does. Rachael pledges her devotion to Adam after he’s diagnosed, then realizes she’s not cut out for such commitment. Kyle, on the other hand, stands by his friend as best he can, encouraging him to use his illness to pick up women and to take advantage of medical marijuana. Things like that play as comedy bits, but you sense the truth behind them. It’s believable that two not-particularly-serious twentysomething men facing this crisis would behave in approximately this way.

To help him cope as he begins his treatment, Adam is referred to a psychologist — or, rather, a grad student working on her doctorate. Her name is Katherine (Anna Kendrick), and she has had exactly two patients before Adam. He finds her eager, textbook-prescribed methodology useless at first, but over time begins to trust her. Adam’s mother (the wonderful Anjelica Huston), already caring for an ailing husband and a born worrier, wants to fuss over her son as much as he’ll let her. And through it all, there’s Kyle, helping in his way. “Fifty-fifty?!” he says optimistically of the survival chances Adam’s doctor gave him. “If you were a casino game you’d have the best odds!”

The film, directed by Jonathan Levine (“The Wackness”), goes mining for laughs in some tender areas without losing its humane point of view. Adam’s coworkers are supportive but perplexed; you get the impression that the series of well-intentioned but inane things they say to him came straight from the screenwriter’s own experience. When Adam starts chemotherapy, he finds that his fellow patients (played by Philip Baker Hall and Matt Frewer) have a dark sense of humor about everything. Again, it feels authentic.

Certain elements of the story that I won’t divulge are more contrived than that, allowing for some too-tidy resolutions of the smaller plot threads. But it’s easy to overlook them when the bulk of the film is so piercingly funny and emotionally honest, with the heartwarming friendship between Adam and Kyle at the center of it. Gordon-Levitt, who is 30, has a baby face that makes his 27-year-old character look about 22, and a slight frame that makes him look fragile even when he’s healthy. As demonstrated in movies like “The Lookout,” “Mysterious Skin,” and “500 Days of Summer,” he’s well-suited to playing characters who are vulnerable or damaged. Seth Rogen, meanwhile, is a big goof who looks older than he is (he’s 29), but who usually has an undercurrent of all-around-good-guy decency in his performances. You think he’s a frivolous lunkhead, and then he surprises you. That’s why it’s so sweet here when Kyle comes around and proves his worth as a real support to Adam.

If you want to get me all choked up at a movie, here are some tips. Show people being kind to one another in the spirit of true friendship. Show someone fighting against suffering he doesn’t deserve. Show a mother’s compassion for her son. Better yet, do all of that, and make it witty and wise to boot. Then call it “50/50” and watch me sob like a little girl.

A- (1 hr., 39 min.; R, pervasive harsh profanity, some vulgar sexual dialogue, brief strong sexuality.)