Twenty-one bodies were awaiting burials when the excavator digging their graves got stuck in the mud.

With armed Liberian soldiers standing guard, the highly infectious bodies — which had been transported from a morgue by truck amid the worst Ebola outbreak in history — were forced to wait in the open until a second digger could be hired and transported to the site.

The burial site itself was controversial; officials transporting the bodies last week were met by protesters from a local village, who believed the site’s proximity to where they live put them at great risk for infection.

Eventually, the villagers relented. Eventually, the bodies were buried, in a scene captured on camera by Reuters.

The episode was emblematic of the logistical problems facing officials trying to cope with the grim task of burying the dead and preventing them from infecting the living as the deadly Ebola virus continues to ravage West Africa.

And those are just the bodies health officials have been able to properly prepare for burial in Liberia, where more than 282 people have died from the disease this year and widespread reports describe Ebola victims laying on the streets for days, increasing the risk of infection by others.

To make things even worse, these logistical issue extend backwards through the Ebola response process, to those seeking treatment. Liberia’s capital city of Monrovia has run out of room for its living patients, as Buzzfeed’s Jina Moore reported:

“In Monrovia, the capital city, there isn’t enough space in the specialized isolation unit to hold all of the city’s symptomatic cases. The Ministry of Health wanted to expand the unit at Elwa Hospital, on the outskirts of Monrovia, but the local community fought back, physically, making it impossible to secure health staff.”

Ebola kills up to 90 percent of those who are infected with it. According to the World Health Organization, the death toll in the current outbreak climbed to 932 on Monday.

Those treating Ebola victims are especially at risk of infection: When a Liberian-American government official named Patrick Sawyer managed to fly to Nigeria with the disease, which is spread only by direct contact with the bodily fluids of a symptomatic victim, several health workers in Lagos fell ill after treating him. Both Sawyer and one of his nurses have since died of the disease and the Nigerian government has declared a health emergency.

But there is a second group of people especially at risk for infection: those who treat and bury the bodies of the dead, which are even more contagious than living Ebola patients.

And a combination of inadequate infrastructure, logistical issues, conflicts with Western health care workers and burial traditions has contributed to widespread difficulties in containing the spread of the disease among mourners and those caring for the dead.

The World Health Organization provides specific guidelines for how to safely transport and bury Ebola victims. They include instructions to “be aware of the [victim’s] family’s cultural practices and religious beliefs,” and to “help the family understand why some practices cannot be done because they place the family or others at risk for exposure.”

Among the traditional practices the WHO says cannot be followed with Ebola victims: family-led body preparation and religious rituals that require direct contact with the corpse. Muslim tradition, for instance, requires that family members of the same gender should wash the body themselves before burial.

There are religiously driven rules about who can handle a dead body, and how. But those rules are often in direct conflict with the procedures health officials must follow to minimize the risk that the disease will spread, because after death is a particularly dangerous time for Ebola infection.

“When the person has just died, that is when the body is most contagious,” WHO spokesperson Tarik Jasarevic told The Post on Thursday. “It’s when the virus is overtaking the whole body.”

The problem is compounded because Ebola can force a victim’s body to release infectious fluids including blood, vomit and diarrhea, especially in later stages of the disease. That includes the most visually harrowing symptom of Ebola, present in some late-stage patients: bleeding from bodily orifices and rashes covering the skin.

Some Ebola victims are sent for burial straight from a treatment center, which minimizes improper handling and exposure to family members. In these cases, as the Red Cross explained, family members often opt to have the bodies of their loved ones buried outside of their communities, in a dedicated space for Ebola victims, out of fear of infecting others.

But when a victim dies in a community, and workers must retrieve the body, the situation is more complicated. In these cases, the Red Cross follows a procedure similar to the one recommended by the WHO: First, the body is repeatedly disinfected. Then, it’s placed in at least two body bags. When the burial happens, anything the body touched — pillows, bedsheets, the protective clothing worn by the workers who prepared it — are either burned or buried with it.

Despite the prevailing narrative of cultural differences presenting a dangerous situation on the ground, Jasarevic, the WHO spokesman, said that his organization believes the bigger problem that there simply aren’t enough trained people on the ground in Liberia, Sierra Leone and Guinea who are capable of dealing with the daily deaths in a proper manner.

“The problem is not so much to explain to people” why some traditional burial practices are dangerous in the case of an Ebola death, he said. Instead, infected areas need teams of trained people “on call, with cars,” who can respond to reports of Ebola infection or death “on short notice.”

Health officials are working on improving response times, but as the burial problems in Liberia have shown, it’s taking too long for trained workers to deal with dead bodies, leading to increased risk of infection and tension with officials once they do arrive.

And in many communities, people blame outsiders for the spread of the disease. People working on the front lines of the outbreak with Doctors Without Borders have described being physically attacked while trying to enter communities with reported Ebola cases. The New York Times reported late last month that Doctors Without Borders has classified over a dozen villages in Guinea as infected but inaccessible because of the group’s hostile reception there.

The WHO’s Jasarevic said international health officials are trying to figure out how to improve local reporting of suspected Ebola cases and deaths within the community. “The problem of reporting itself was a problem, but I think the communities understand now,” he explained. In other words: more communities are reporting their dead, even if the system itself isn’t perfect.

But success rates vary country to country. In Sierra Leone, Jasarevic said, the WHO is identifying and training villagers to report dead bodies and suspected cases to officials — and it’s working relatively well.

“It’s really like organizing surveillance,” he said. Trained reporters are often given mobile phones and “maybe some money” as an incentive to report deaths and suspected cases to authorities, Jasarevic added.

The Red Cross also singled out Sierra Leone as a relative success case. Officials there have created “dead body management” teams, often staffed by paid members of the community, to bury the dead, and the system seems to be improving overall.

But, said Red Cross team leader Daniel James: “There are still many other communities who do not believe Ebola is real, and who continue with the local custom of preparing bodies for burial themselves.”