Meilin Keen was studying for the bar exam and preparing to move to New York City last June when she started throwing up blood.

Keen, 27 years old, learned days later that she has gastric cancer. She postponed the bar exam. Brain fog from chemotherapy made it hard to do her legal work.

Surgeons removed her stomach in December. Keen is coming to terms with all that means for her diet, her health, even her dating life. “That’s a fun icebreaker: I don’t have a stomach anymore,” she said.

Cancer is hitting more young people in the U.S. and around the globe, baffling doctors. Diagnosis rates in the U.S. rose in 2019 to 107.8 cases per 100,000 people under 50, up 12.8% from 95.6 in 2000, federal data show. A study in BMJ Oncology last year reported a sharp global rise in cancers in people under 50, with the highest rates in North America, Australia and Western Europe.

Doctors are racing to figure out what is making them sick, and how to identify young people who are at high risk. They suspect that changes in the way we live—less physical activity, more ultra-processed foods, new toxins—have raised the risk for younger generations.

“The patients are getting younger,” said Dr. Andrea Cercek, who co-directs a program for early-onset gastrointestinal cancer patients at Memorial Sloan Kettering Cancer Center in New York, where Keen was treated. “It’s likely some environmental change, whether it’s something in our food, our medications or something we have not yet identified.”

Actor Chadwick Boseman’s death at 43 from colon cancer in 2020 drew public attention to the rising prevalence of colorectal cancer in people under 50, a trend that first alarmed oncologists during the prior decade. They soon realized the crisis extended to some other cancers, including pancreatic, appendix, stomach and uterine.

“Colorectal cancer was the canary in the coal mine,” said Timothy Rebbeck, a cancer epidemiologist at the Dana-Farber Cancer Institute in Boston.

The U.S. cancer death rate has dropped by one-third since 1991, thanks to a plunge in smoking and better treatment. Screening to catch cancers earlier, including breast cancer, has helped, too.

Although cancer still strikes older people far more often than the young, the rise in early-onset cancers threatens to stall progress. One in five new colorectal cancer patients in 2019 was under 55, a near doubling since 1995. These younger patients are often diagnosed at late stages. Colorectal cancer death rates among patients over 65 are going down, but for those under 50 they are going up.

“We are seeing more and more young people who don’t fit the classic teaching that cancer is a disease of aging,” said Dr. Monique Gary, medical director of the cancer program at Grand View Health in Pennsylvania.

Keen had weathered heartburn and acid reflux since high school. She took antacid tablets for months while studying for the bar exam. She lost her appetite. When she vomited blood, she thought she had drunk too much coffee.

When she started seeing white and feeling as though she might pass out, she went to the emergency room.

At the hospital, doctors stabilized her and ran tests to figure out what was wrong. When a doctor suggested a cancer-causing bacteria might be the culprit, Keen was so surprised she almost laughed.

“I didn’t really think that much about cancer until I got it,” Keen said. “It messes with your identity.”

Not all cancers are on the rise among young people. Breast cancer, the most common cancer diagnosis in the U.S. for people under 50, is rising some, and gastrointestinal cancers like Keen’s are increasing the fastest, studies suggest. Hoping to capture more cases sooner, medical groups have lowered to 40 the recommended age for breast-cancer screening to begin, and for colorectal cancer, to 45. Some people who get diagnosed at an advanced stage are still too young for such screenings to be recommended.

Doctors are desperate to figure out what puts people at higher risk.

“If we’re not understanding what it is now, there’s another whole generation that’s going to be dealing with this,” said Dr. Kimmie Ng of Dana-Farber.

Ng was among the first oncologists to investigate a troubling rise in colorectal cancer cases, which she has seen in her own patients over the past decade. One of them was Patrick Beauregard, a Marine diagnosed with colorectal cancer in 2017, at 29. A bout of intense stomach pain had sent him to the E.R. two weeks after his honeymoon.

Beauregard and his wife, Amanda Beauregard, had a son during his treatment. Beauregard died less than two months later, in 2020. Last year, Amanda had their second son using in vitro fertilization. Much about the boys reminds her of her husband, including their love of Halloween and “The Nightmare Before Christmas.”

“He would have been such an amazing and hands-on dad,” she said.

The risk of developing some cancers at a young age has increased for each generation born since the 1950s, studies suggest. One found that people born in the 1990s are at double the risk for early-onset colon cancer and four times the risk for rectal cancer, compared with people born around 1950.

“We have to find out why,” said Ahmedin Jemal, an author of the study and a senior vice president at the American Cancer Society. “Otherwise, the progress we have made in the last 50 years may stall or reverse.”

Cancer starts with genetic mutations that spur cells to multiply uncontrollably, spreading and forming tumors. Such mutations pile up as we age, so cancer risks do, too. For more young people, though, something is triggering that cascade of haywire cellular production earlier.

Researchers are scrutinizing possible causes ranging from inactive lifestyles to microplastics. Oncologists have found a greater risk of developing colorectal cancer at a young age among women who spent a lot of time sitting in front of the TV. Drinking sugary drinks in high school correlated with higher risk, too. Even being born via caesarean section seemed to link another group of women with higher risk of getting colorectal cancer early.

Deep-fried and highly processed foods have been implicated in other studies of early onset colorectal cancer, while diets with fiber, fruits and vegetables likely lower risks. Cancers including colorectal, breast and pancreatic have been tied to obesity, and studies support a link between excess weight and some early onset cancers.

But doctors said obesity and lifestyle can’t fully account for the plight of the people arriving at their clinics.

“A lot of the young patients are very healthy,” said Dr. Y. Nancy You, a colorectal cancer surgeon at the University of Texas MD Anderson Cancer Center in Houston.

The first patient You saw at the cancer center more than a decade ago was 48. He had a genetic disorder that explained why he developed cancer so young.

Then, there was the 37-year-old who competed in Ironman triathlons. After that, a 40-year-old, uninsured single mother who had made three trips to the E.R. for rectal bleeding. She arrived at You’s office with rectal cancer that had spread to her liver.

You and her colleagues have studied bacteria and other microbes in tissue samples from rectal cancer patients. They found differences based on age. You said changes in the makeup of microorganisms in the digestive tract spurred by diet, antibiotic use or other factors might drive inflammation and increase cancer risks.

Some doctors suspect that cancer-causing exposures might have started during patients’ childhoods, something that is difficult to trace. Unlike when smoking drove up lung cancer deaths in the 20th century, doctors suspect there isn’t a single carcinogen responsible for the current trends. Some worry young people’s rising cancer risks are a sign of deeper trouble.

“Is it part of a larger trend of, are we just getting unhealthier?” said Dr. Sachin Apte, chief clinical officer at Huntsman Cancer Institute at the University of Utah.

Researchers at Vanderbilt-Ingram Cancer Center in Nashville are recruiting U.S. appendix-cancer patients to provide saliva and tumor samples to learn more about the rare disease.

Other cancer centers are tracking groups of patients over time. Doctors at Memorial Sloan Kettering are collecting tumor samples and asking young patients about exposure to possible risks, from alcohol to anxiety medication. They are probing patients’ origins, too: How old were your parents when you were born? Were you breast-fed?

Keen was born in China and adopted when she was 2 by parents who raised her in Iowa. Her cancer was linked to H. pylori, a bacteria that causes ulcers. Keen suspects she picked it up in an orphanage in China, where the infection rate is higher.

After her June diagnosis, Keen started hormone injections to improve the odds she could get pregnant after chemotherapy. But the injections were expensive and exhausting, and Keen wasn’t certain she wanted to have children. She stopped after a few weeks.

Keen and her cat Pudge moved to an apartment in Manhattan close to the cancer center. She threw herself into cancer support groups.

During chemotherapy, Keen gained weight and lost her long black hair. When it started falling out, friends filled her apartment to help her cut it. Keen went alone later to get the remnants buzzed off. She cried in the salon chair. “It felt like I was losing a part of myself,” he said.

Keen wore a wig under a hat when she met law-school friends on a Saturday night in December at a favorite Chinese restaurant in Brooklyn. She wanted a decadent meal to celebrate her stomach before it was removed.

They ate family style. Keen knew everyone’s favorite dishes, ordered seconds and led a round of guessing the bill. It might have been a typical Saturday night for a group of 20-somethings in New York.

A few days later, Keen and her parents trekked before dawn to Memorial Sloan Kettering for her 5:30 a.m. surgery. Hours later, she woke up in a hospital bed in pain with a row of stitches up her abdomen.

Her stomach was gone, but so was her cancer. Keen will get scans and blood tests every few months to make sure cancer hasn’t reappeared.

Surgeons had stitched her esophagus to her small intestine, which absorbs most nutrients. The first week after surgery, it felt like food was getting stuck in her throat. She learned to eat slower, avoiding bread, meat and sugar for now.

“I ate a whole bag of gummy worms and paid the price,” she said.

Keen is going to restaurants again, sticking mostly to appetizers, and is walking for exercise. She re-downloaded dating apps. Keen included her diagnosis in her profile. Some responses made her cry. Her matches were nicer than before her cancer. She has been on a few dates.

Keen had worried her diagnosis would delay her life, and it had. But it also redirected her, she said: “I’m more intentional.”

Her hair is growing back. Keen plans to take the bar exam this July.

Write to Brianna Abbott at brianna.abbott@wsj.com