DAKAR, Senegal >> When a fisherman showed up for work on a recent morning at a popular beach in Dakar, the capital of the West African nation of Senegal, he found a horrifying scene: Dead bodies splayed across the sand, and a painted wooden boat bobbing unattended.

He plunged into the water to help search for survivors. The pirogue, a wooden fishing boat, had been loaded with migrants hoping to reach Spain, but instead it struck a ring of underwater rocks on July 24.

At least 16 bodies were recovered — the latest in a string of tragedies to befall people risking the treacherous ocean route to Europe.

This boat, however, was being chased by patrol vessels from Spain and Senegal in near total darkness when it hit the rocks, according to a witness who was on the beach and the leader of a local aid group who has spoken with survivors. The deputy mayor for the area also said in an interview that the boat was being pursued.

“This could have been avoided,” said the fisherman, Pape Djibril Samb, who was among the lifeguards, exercisers and other fishermen who are regulars on the beach but helped retrieve bodies.

Senegalese officials said they were investigating, and declined to comment. A spokesperson for Spain’s interior ministry, who declined to be named in keeping with the ministry’s policy, denied in an email that a Spanish patrol vessel pursued the pirogue, saying their patrol boat alerted Senegalese authorities on land that a boat was sinking after it ran aground.

The tragedy at a beach beloved by runners and fishmongers, at the foot of the towering Mosque of the Divinity, shocked a nation accustomed to hearing about deadly events involving boats leaving Senegal packed with people heading for Spain, often via the Spanish Canary Islands. In just June and July, at least 547 people died in boats that left from Senegal, according to a tally from the Spanish aid group Walking Borders.

Patrols on the water have been rising in recent months, said local aid groups. They worry that new resources devoted to stopping migration will lead to more dangerous situations.

The accident raises difficult questions about how best to respond to the increasingly deadly crisis of irregular migration, and shows how some aggressive efforts to curb arrivals can backfire.

For the migrants on the pirogue off Dakar, the terror unfolded in the early morning darkness not more than 50 yards from shore.

The witness said he was on the beach when he heard screaming. He could not be identified by name because he fears angering Senegalese authorities. The New York Times talked to workers on the beach who said he had told them the same version of events that morning.

The witness said he rushed to find bodies in the water and a rocking pirogue, with two navy vessels behind it shining floodlights on the scene and trying to pull aboard struggling people.

At the same time, the man said, dozens of people made it to shore and began running away.

He said he immediately phoned the police, who told him the pirogue in the water was the same boat that both Senegalese and Spanish ships had been pursuing. He stayed at the beach to pull in bodies. He also talked with one of the survivors, whose legs and feet were covered in sea urchin spines. He needed medical attention, and police eventually took him to a hospital.

He said the survivor told him patrol vessels had been pursuing their fishing boat, and the captain had been hurriedly trying to navigate to the beach so everyone could escape by land, rather than face arrest.

The witness said that a white man speaking Spanish into his mobile phone arrived at the beach that morning in a 4-by-4 vehicle, and immediately approached police at the scene.

The small bay where the episode unfolded is lined by a ring of volcanic rocks well known to the fishermen who work there, but nearly impossible to see at night. The water is deep where the boat spilled; people who helped recover bodies say the dead most likely could not swim.

Samba Kandji, deputy mayor of the area where the accident happened, was at the beach after the incident, and said police told him the boat had been pursued. He did not know which country the patrol vessels came from.

The Spanish Interior Ministry spokesperson pointed to data collected as of July 31 that showed a decrease of 3.3% of illegal arrivals to Spain in the last year. He attributed the decline to the bilateral cooperation between Senegal and Spain.

However, as climate change shrivels crops and rising sea temperatures threaten fish stocks, the many Senegalese who make their livings farming and fishing may consider fleeing.

The pirogue that hit the rocks in Dakar, painted in swirls of reds, yellows and blues, hung in the water for days after the accident, a haunting, half-submerged reminder of a potential outcome of migrating by sea.

Ibrahim Pape Ndour, a fisherman, sat with his crew on that beach on a recent afternoon in a cabana mending their turquoise net that had been severed by a giant trawler. Their work yields much less fish than in the past, Ndour said, blaming overfishing and plastic in the ocean.

He had helped to search for bodies from the pirogue that hit the rocks. But even he has dreams of Europe.

“Bring a boat right now, you’ll see. We’d all go,” he said, pointing to his crew. “Death is easy.”