Climbing up around 7,000 feet over the Atlas Mountains, the road through the Tizi N’Test pass bends impossibly around cliff edges, expands and pinches uncomfortably to a single fragile track, and creeps under jagged rocky outcrops.

For a century now, the stretch of lonely road has been known for its stunning views and perilous turns. That all changed on Sept. 8, when an earthquake struck Morocco, killing at least 2,900 people, and bringing down dozens of villages perched high along the edges of the road.

Then, the serpentine road became a vital lifeline — the conduit to lifesaving ambulances and essential aid to devastated villages in the mountains. But first, it had to be reopened.

Just hours after the earthquake struck on Sept. 8, construction crews set out in graders, diggers and dump trucks to start the difficult and dangerous task of clearing the road of giant boulders shaken loose by the tremors and sent crashing down the mountainsides, crushing buildings on their way.

The work has not stopped since.

“We won’t sleep until we clear the road,” Mohammed Id Lahcen, 33, said on Friday, sitting on a pile of broken rocks beside the hulking grader he’d been operating for the past week.

Mr. Id Lahcen and his team managed to carve out enough space for some vehicles to pass after several days of labor, but they were still working to clear the boulders and debris pushed to the road’s edges. He said he had only taken breaks to dash out of the way of the slabs of rock that keep smashing down the mountainsides, nibble food and snooze in his grader. He hadn’t been home to shower or change clothing.

In many areas hit by the quake, there were complaints that the government was slow to rescue and bring relief supplies to stricken villages. That left it to residents to dig out victims themselves and fellow Moroccans to bring food, blankets and mattresses.

Driving along the road to the Tizi N’Test pass, the challenges faced by relief workers getting through became clear.

For days, concerned Moroccans from far-off places like Rabat, hundreds of miles away to the north, packed their cars and trucks with donations, and then cautiously navigated their way up the road to Mr. Id Lahcen’s machine, hoping to offer help and comfort to villagers who were still cut off. Upon seeing the blocked road, they begged Mr. Id Lahcen and his colleague, Mustapha Sekkouti, to help get their bags of supplies to the other side.

“This reality, we want it to be a memory in our history,” said Mr. Sekkouti, 50. “I want to be able to tell my grandchildren that I was here. Helping clear the road to save lives.”

The efforts by Mr. Id Lahcen and Mr. Sekkouti opened a gap near the top of the road on Sept. 11, allowing some aid to get through. However, temporary closures and jams that slowed traffic continued for days, forcing The New York Times to abort an initial attempt to reach the summit.

By Friday and Saturday, however, we were successful, traveling the full length of the road, 112 miles from the town of Oulad Berhil over the mountains north to Marrakesh, making stops along the way. The trip revealed a country that was emerging from the horror of an emergency, and taking the first difficult steps toward a recovery.

The road was clear, mounds of rubble pushed to its gnawed edges, and dotted with heavy machinery. Alongside rose the ruins of mud brick homes that had melted into their mountain perches and lines of large yellow and blue tents where survivors were now living.

Women carried pillows, mattresses and bags of donated clothing up its sides. Flatbed trucks crowded with stacked school desks and chairs rolled toward a cluster of tents in Asni, a town where high school and middle school students were preparing to start their school year on Monday.

A military field hospital, erected near the southern end of the regional road in the small town of Tafingoult, appeared to be quiet — just one bed in its air-conditioned emergency tent was occupied, and the sterile operating room was empty. Erected less than two days after the earthquake, the hospital had received some 600 patients for trauma — fractured bones, perforated stomachs, broken backs. Most had been sent to permanent hospitals or discharged.

“We are dealing mostly with chronic conditions now,” said Dr. Noureddin El Absi, pointing to an older patient being treated for advanced diabetes, exacerbated since she had lost her medication in the rubble of her home. The worst is over, he said, and the worst had thankfully not come. Not a single patient they had treated so far had tested positive for the coronavirus.

Up near the top of the mountain pass, Hassan Ikhoudamen, 36, was sweeping up the broken glass bottles and dented soda cans that had tumbled off the shelf behind the bar of his cafe and modest guesthouse the night of the earthquake.

A week later, he deemed it was time to reopen his cafe.

He considered himself lucky: Though his house was destroyed, his wife and three sons had survived, and the cafe he had run for 11 years had suffered only cracks.

“The most important thing is to fix the building before winter,” Mr. Ikhoudamen said.

Eager for a distraction from the misery they had witnessed, a group of young men from a nearby destroyed village arrived to play pool and hang out on the cafe’s couches.

“Death is not here,” said one, smiling.

About 20 minutes down the road in what remained of the village of Tinmel, Soufiane Aarrach, 26, dug through the rubble of his older brother Abderahim’s bedroom, searching for identity papers so he could declare him deceased.

Abderahim was one of 45 people working to restore an ancient mosque nearby and was killed when the earthquake struck. The back half of the mosque, built more than eight centuries ago, was destroyed — as was the back of a house across the street where Abderahim was renting a room with his closest childhood friend, Mohamed El Ouaryky, who was also working on the renovation.

Their lifeless bodies had been found entwined in the rubble of their shared bedroom, Mr. Aarrach said.

“They were scared,” he said. “They were protecting one another.”

He dug in the rubble of the house in plastic slides, shoveling bricks and earth onto a growing mound of detritus, until he uncovered a sealed bag. Inside were clothes — a leather jacket, a white shirt, some beige pants. He pressed the shirt and pants to his face and inhaled deeply, his eyes filling with tears.

“These were my brother’s,” he said. “I said a prayer for him.”

Down toward Marrakesh, where the route generously broadens and flattens, the village of Tijghicht revealed just how vital access to the road is.

Giant boulders had blocked the way after the earthquake, leaving villagers to dig through the destroyed houses for survivors and their deceased neighbors on their own with just a pair of shovels.

They fashioned makeshift stretchers out of wooden poles and rope, and carried the badly injured more than six miles to a nearby town on the main road.

On the fourth day after the earthquake, the mayor, Bouchaib Igouzoulen, lay down before a giant digger on the main road and refused to move until it churned toward Tijghicht. The next day, the road was cleared enough to allow ambulances through.

Since then, the villagers have resettled on some farm fields along the edge of the river below the remains of their homes. They’ve erected a row of tents — one for each family — under solar-powered lamps, brought in water from a nearby source with a long hose and organized rotations of cooks to make meals for 250 people over wood fires.

Leading a tour, Mr. Igouzoulen alternated between horror and hope, introducing neighbors still in shock from the sudden loss of a grandchild, a mother or, in the case of 15-year-old Mourad Ouhida, his entire family. Mr. Igouzoulen held the boy close, trying to comfort him.

Now that his village was reconnected to the main road, the mayor was setting his mind to the future — how to rebuild his village, and where.

These are decisions and plans that will take time. In the coming months, snow will make much of the road slippery and, at times, impassable again.

“We need to start today,” he said.