People who became infected with Covid-19 after getting a messenger RNA vaccine carried less virus and had shorter cases than unvaccinated people who became infected, a study by government health researchers found.

Sixteen people in the study who got infected, despite taking a Pfizer Inc. or Moderna Inc. vaccine, had on average 40% less virus in their nose compared with the 155 unvaccinated people who became sick, according to the study, published online Wednesday in the New England Journal of Medicine.

The vaccinated individuals also had a 66% lower risk of having detectable virus for more than one week, and they had a shorter duration of illness, with about two fewer days spent in bed, the study said.

The findings provide further evidence supporting what health authorities promoting vaccinations have been saying for months: While getting vaccinated can’t prevent all cases, the relative few that develop tend to be milder.

“Even when people get vaccinated and did get infected, they were less likely to have an illness that causes a fever,” said Mark Thompson, an epidemiologist at the U.S. Centers for Disease Control and Prevention who helped lead the study.

The findings also lend some support to evidence indicating that vaccinated people who are infected don’t transmit the coronavirus as much as the unvaccinated.

“There’s reason to think that even if you get infected, you have less virus to spread around and infect other people,” Dr. Thompson said.

The results were from a broader look, led by the CDC, at real-world use of the mRNA vaccines from Pfizer and its partner BioNTech SE, and from Moderna.

For the study, researchers enrolled about 4,000 healthcare workers, first responders and essential workers, and found 204 of them became infected with Covid-19. Of that group, 155 people were unvaccinated and 16 had received at least one mRNA shot.

Researchers said they excluded data from the remaining study subjects because their vaccination status couldn’t be determined.

Five of the vaccinated subjects who became sick received both doses of the two-dose vaccines, while the rest had received their first shot. None of the vaccinated people who became infected were hospitalized, as they all had mild or moderate cases, Dr. Thompson said.

Researchers took samples from study participants before the Delta variant is believed to have arrived in the U.S., Dr. Thompson said.

Researchers sequenced 10 of the 16 breakthrough cases, Dr. Thompson said. They found only three variants among them, all involving the Epsilon variant that was first identified in California.

The study also found the vaccines were 91% effective at preventing infection among fully-vaccinated healthcare workers, first responders and other essential workers, results in line with data released earlier this year.

The vaccines were 81% effective among individuals who were partially vaccinated, the study said.

Write to Jared S. Hopkins at jared.hopkins@wsj.com