When the gay couple, both hairdressers, heard that the 7-year-old boy living downstairs had been stricken with cancer, they cut off a lock of his red hair and brought it to a friend, who made a wig that was a perfect match.

When the boy would fall asleep in math class because the chemotherapy had made him so weak, the nuns would instruct his classmates to keep doing problems on the board, not to point and stare.

The older boys at the playground would defend him if anyone tried to subject him to the kind of teasing that was a neighborhood rite of passage. Knock it off, they’d say. He’s had it tough.

Martin J. Walsh’s Dorchester neighborhood — filled with Irish immigrants, police officers, firefighters, and construction workers — nurtured and protected him as he hovered on the edge of death and formed his earliest and deepest sense of community. That neighborhood, Savin Hill, remains his home and a touchstone for Walsh, as he seeks to be the next mayor of Boston.

Get Political Happy Hour in your inbox:

Your afternoon shot of politics, sent straight from the desk of Joshua Miller.

Before busing and gentrification ripped apart the neighborhood, Walsh, 46, grew up in a Dorchester where families with 12 children were not uncommon, doors were unlocked, and the streets teemed with boys and girls playing kick-the-can and hide-and-seek.

But within that cloistered corner in the shadow of St. Margaret Church, young Marty Walsh was different. After four years of chemotherapy forced him to miss most of second and third grade and to repeat the fifth, his recovery from Burkitt’s lymphoma was considered by many evidence of divine intervention.

Martin J. Walsh was diagnosed with lymphoma at age 7.

“People would say, ‘Oh, you know he was sick,’ ” said Anne Nee, who was the director of the community center, lowering her voice to a hush. “ ‘He’s a miracle.’ He was special that way.”

In some ways, Walsh’s family was like many others in the neighborhood. His parents, Mary and John, immigrated from Galway, Ireland, in the 1950s. She was a homemaker, he was a laborer, the trade his son would join decades later.

Dinner was on the table at 5 o’clock sharp, seven days a week, and Martin and his younger brother, John, were expected to be there. Most of Walsh’s free time was spent at the Little House, the community center where he took woodworking classes and played Wiffle ball, or at St. Margaret, where Walsh, a chubby boy with a bowl cut, danced the jitterbug in parish-sponsored musicals.

“The nuns loved him,” said Frank Baker, a city councilor who grew up with Walsh. “He was that nice kid. He had a face that they just loved.”

Beyond the steady rhythms of Walsh’s life, the neighborhood was changing. Families began fleeing to Quincy and Weymouth when the busing controversy erupted in 1974, the same year Walsh received his diagnosis.

His teacher at St. Margaret School, Sister Theresa Joseph, recalls ushering Walsh’s class off the playground and into the church when buses carrying children from Roxbury would roll past on their way to South Boston. Police cruisers, sirens wailing, would block off the intersection outside the church to protect the buses, terrifying Joseph’s students.

“The busing did a terrible job on us,” she said. “The times were bad — it was get out of Boston, get out of Dorchester, and get away from the busing.”

When Walsh started feeling sick that October, a cousin thought he might have gotten food poisoning from a pizza. But Mary Walsh remembers how a doctor at Children’s Hospital, suspecting worse, whisked her oldest son into surgery and emerged with a grim face.

“When he came out, he said, ‘We just closed Martin up now, and I don’t have good news for you,’ ” she said. “ ‘There are thousands and thousands of cells of cancer all over his bowels, his pancreas, and all over his body.’ ”

Then the doctor took aside Martin’s father and told him the boy had six weeks to two months to live. Walsh began radiation treatments and chemotherapy.

Mary Walsh and John Walsh, immigrants from Ireland in the 1950s, visited their homeland with their son Martin. She was a homemaker and he was a laborer.

“It was awful,” Mary Walsh said. “He lost so much weight. Oh, my God. He was so skinny.”

Walsh lived mostly at Children’s Hospital. He recalled subsisting largely on Starburst candy, a child’s act of rebellion against the steaming hospital food that arrived on plastic trays.

Three miles away in Dorchester, everyone had heard about the Walsh boy from Taft Street, the one with cancer. Nuns from St. Margaret School made pilgrimages to his bedside, leaving candles and Mass cards. The children at St. William Parish, a neighboring church, sent him get-well cards. Aunts, uncles, cousins, and neighbors came to say prayers.

“I can still see him in my mind, lying in the bed with his little red head,” said Francine Barron, a neighbor who would visit Walsh after work. “That was a scary time.”

On Thanksgiving, Walsh’s family, which had been planning to celebrate the holiday at his bedside, got a small reprieve when doctors told them they could take Martin home for four hours.

“We were so happy, and everyone came with food, with all his aunts, uncles, cousins — you name it, they were here,” Mary Walsh said. “When it was time for him to go back, he was always so brave, he said, ‘Now, I think it’s time for me to go back.’ I will never forget that.”

Walsh attended school sporadically, but Sister Joseph recalls him being so sapped of energy, he would fall asleep in her math class. The other boys would give him a nudge, she said. Some days, Walsh was so weak, the nuns would call his mother to come and take him home.

One day, the two hairdressers who lived on the top floor of Walsh’s three-decker noticed that the child’s hair was falling out, and one of them offered to help.

“He said, ‘Is it all right if I take a little piece of Martin’s hair?’ ” Mary Walsh said. “So he took a piece of the hair and he sent it to New York and, one evening, he came down with the wig, and it was perfect. The same exact color, and everything. And he said, ‘This is for Martin, and it’s on me.’ ”

JESSICA RINALDI FOR THE GLOBE

When Walsh was 17, he waged a campaign to save Saturday floor-hockey games at the Little House.

Sister Joseph recalls Walsh wearing the wig in school. “The kids didn’t know the difference, but the teachers did,” she said. “We were very protective of Marty.”

Walsh’s memories of that time are snippets rather than full recollections — images from a young boy not fully aware of the gravity of his illness. He remembers not being allowed to play ice hockey or Little League, and being embarrassed to wear the wig in school. He remembers doctors pricking his arms with needles, and Bobby Orr stopping into his hospital room.

“I didn’t know at the time that I was potentially dying,” he said. “As a little kid, nobody was talking to you about it. It was a way of life.”

In December, the priest at St. Margaret decided to move Walsh’s first Communion to the 11 a.m. Mass on Christmas Day. He and the family agreed they could not want to wait until May, when Walsh’s class would celebrate the sacrament.

Walsh’s grandmother came from Ireland, and the neighborhood filled the church’s pews to watch Martin ascend the altar.

“It was unbelievable,” Mary Walsh said. “I kept up very well, but it was very emotional for the people in the church.”

Despite his illness, Walsh’s family tried to keep his boyhood as normal as possible. Walsh’s father and uncle Pat, who was the head of the laborers’ union, loved to jaw about campaigns around the house, giving him his first taste of politics.

Walsh recalls his father taking him to a rally for Joseph Timilty in his 1975 race against Mayor Kevin H. White, and to a warehouse in South Boston, where he used an ink roller to print red-white-and-blue signs for Edward J. King when he defeated Governor Michael S. Dukakis in 1978.

Slowly, Walsh’s health began to improve. He started gaining weight, and even playing sports. Doctors say that Burkitt’s lymphoma, while aggressive, often responds well to chemotherapy, and Walsh’s did.

When he was 11 — four years after he was diagnosed with cancer — a scan revealed the full extent of his recovery. “The doctors were amazed, because there wasn’t a trace of cancer, or tumors, or anything,” Mary Walsh said.

To mark Walsh’s recovery, the priest led a parish trip to Disneyworld, Joseph said, adding that she had heard that the priest’s sister had paid for the Walsh family. Mary Walsh took her son to the shrines at Knock in Ireland and Our Lady of Lourdes in France.

As the months and years passed, Walsh’s identity was less and less tied to cancer. He grew into a teenager with a Mercury Grand Marquis and a steady girlfriend.

Some of his friends didn’t even know he had been sick. One remembered him showing up at “the beams” — the local hangout underneath the old elevated Central Artery — where teenagers would drink beer and set Christmas trees on fire after the holiday.

But Walsh was not considered an instigator of mischief. He attended Newman Prep, a private school in the Back Bay that cost about $1,000 a year. After school, friends recall Walsh driving them in the Marquis to watch Bruins games from cheap seats with obstructed views or to see movies in Somerville and Revere.

“We were kind of the nerds,” said Tom Murphy, a friend. “We weren’t hanging on the corner, or down at the park.”

It was about that time that Walsh started to hone what would later become his political instincts, as a coach in Catholic youth league sports.

When he was 17, he waged what could be considered his first political campaign, a bid to save Saturday floor-hockey games at the Little House.

The games, which had been a popular pastime at the community center for 20 years, had been canceled because of dwindling attendance. Walsh was so upset, he posted fliers and went door-to-door in the neighborhood, recruiting new players, said a friend, David Doyle.

Walsh also began stepping into neighborhood disputes. When two 11-year-olds, one white and one black, began fighting at the Little House, Walsh took them to a Burger King. Even though the boys were famished, Doyle said, Walsh made them work out their differences before he would buy them Whoppers.

As Walsh’s friends began planning to become firefighters and funeral home directors like their fathers, Walsh began talking of a different future for himself — in elected office.

“He used to say, ‘I’m going to be mayor some day,’ ” Murphy said. “And we’d laugh it off as teenagers, like, ‘Yeah, yeah. Whatever.’ ”

These days, no one is laughing. The friends, neighbors, and teachers who prayed for Walsh when he was struggling with cancer are holding signs and making phone calls for his mayoral campaign.

While many candidates rely on relatives and friends, it is striking just how many of the loyal foot soldiers in Walsh’s operation have known him since he was a boy.

Many are proud that a candidate who came from the heart of Dorchester — a three decker on Taft Street with a narrow concrete alleyway — has a chance to lead the city.

“A lot of people are thrilled with that,” said Pat Flaherty, 90, a retired inspector at the South Boston Army base, who has lived next to the Walsh family on Taft Street for six decades. “To see that a neighbor — let’s face it — could be mayor of Boston. And a three-decker neighbor, not a one-family house neighbor.”

BostonGlobe.com complimentary digital access has been provided to you, without a subscription, for free starting today and ending in 14 days. After the free trial period, your free BostonGlobe.com digital access will stop immediately unless you sign up for BostonGlobe.com digital subscription. Current print and digital subscribers are not eligible for the free trial.

Thanks & Welcome to Globe.com

You now have unlimited access for the next two weeks.

BostonGlobe.com complimentary digital access has been provided to you, without a subscription, for free starting today and ending in 14 days. After the free trial period, your free BostonGlobe.com digital access will stop immediately unless you sign up for BostonGlobe.com digital subscription. Current print and digital subscribers are not eligible for the free trial.