CAPE TOWN — A musician from South Africa had a tumor in his brain, so doctors opened a hole in his skull to remove it. But they had a crucial request: He must play his acoustic guitar during the surgery.

The musician, Musa Manzini, a jazz bassist, was awake when the doctors performed the surgery last week, and video footage from the local media site News24 shows him strumming an acoustic guitar slowly as they operated.

The technique, known as “awake craniotomy,” allows doctors to operate on delicate areas of the brain — like the right frontal lobe, the site of Mr. Manzini’s tumor — without causing damage. Presumably, had he hit a wrong note, it would have been an immediate signal for the surgeons to probe elsewhere.

“It can be very difficult to tell the difference between the tumor and normal brain tissue,” said Dr. Basil Enicker, a specialist neurosurgeon who led the operation at Inkosi Albert Luthuli Central Hospital, in the coastal city of Durban. “Once you’re near a critical area, you can pick it up early, because he will tell you.”

The surgery is not unusual. The first craniotomies date to prehistoric times, with fossil records showing that patients had holes drilled in their skulls — and survived — as early as 8,000 years ago. In the 1930s, the Canadian-American neurosurgeon Wilder Penfield pioneered modern craniotomies, which he used to treat epilepsy.

The procedure has become fairly common globally since then, posing no greater technical challenge than regular brain surgery, Dr. Enicker said. But choosing patients is very important: People who cough, for example, or who cannot lie still for extended periods, are far more dangerous to operate on.

Mr. Manzini is not the first musician to be asked to perform during brain surgery. In 2014, a tenor in the Dutch National Opera, Ambroz Bajec-Lapajne, sang Schubert’s “Gute Nacht” as doctors removed a tumor.

In 2015, the saxophonist Carlos Aguilera read music and performed during an operation in Spain.

And a Washington teenager, Kira Iaconetti, who had a rare form of epilepsy that triggered seizures, was asked to sing through brain surgery at Seattle Children’s Hospital.

The doctors who treated Mr. Manzini were concerned about the motor function of his left hand, said Dr. Rohen Harrichandparsad, another surgeon on the team. “We wanted to make sure we took as much of the tumor as we safely could, but preserve his dexterity,” he said.

For a professional musician like Mr. Manzini, whose work requires coordinated activity across multiple regions of the brain, there were further complications.

“We had to ensure that whatever pathways he was using for music were preserved,” said Dr. Harrichandparsad. “There’s no single pathway, but a multitude that interact.” It would have been “impossible to do this,” he added, without Mr. Manzini’s remaining awake.

First, the doctors placed Mr. Manzini under intravenous anaesthetic, gently waking him once they had exposed his brain. Sensitive nerves in the surrounding skin, muscles and membranes were dulled by injections of local anaesthetic. But “once we’re in the brain, there’s no pain,” Dr. Enicker said, as the brain has no pain receptors of its own.

Using small electrodes, the surgeons stimulated different parts of Mr. Manzini’s cortex, testing which areas were functional in a process known as cortical mapping.

“The hand would sort of move automatically by itself,” Mr. Manzini recalled in a phone interview on Friday. “It’s very funny and strange.”

Next, the doctors handed Mr. Manzini a guitar and asked him to play while they excised the tumor, ensuring that they were not removing any critical tissue. It was difficult to concentrate, Mr. Manzini said, with what felt like a “blowtorch” inside his head.

“There’s this loud sucking sound and stuff, yet I don’t feel no pain at all,” Mr. Manzini said, referring to the vacuuming device used to remove blood while the surgeons operated. “It’s like you’re in between being dead and being alive.”

Doctors discovered the tumor in 2006, and Mr. Manzini had undergone two surgeries under general anaesthetic. Earlier this year, he said, his left hand began feeling “numb and clumsy” while he was playing guitar, and when scans showed that the growth had returned, he opted for an awake craniotomy.

“I watched quite a lot of YouTube videos to prepare myself mentally,” Mr. Manzini said.

Dr. Enicker estimated that his team removed 90 percent of the tumor before yielding to caution and stitching up Mr. Manzini. The musician remained awake until the end. He was discharged a few days later and is recovering at home in Durban.

“I’ve been given a new opportunity,” Mr. Manzini said.

In the mold of Stanley Clarke or Jaco Pastorius, Mr. Manzini plays his bass guitar like a lead instrument. He has released four albums and lectures about bass guitar at the University of KwaZulu-Natal.

Before operating on Mr. Manzini, neither Dr. Enicker nor Dr. Harrichandparsad had come across his music.

“I’ll be looking forward to being invited to his first concert after surgery,” Dr. Harrichandparsad said.