Violent crime dropped sharply this year in San Francisco, with killings in 2018 approaching the lowest number in more than 50 years to continue a decade-long trend of declining violence around the region.

Identifying precise causes for crime trends has been a long-standing challenge, but the city’s police officials believe several recent initiatives — including a new gun unit whose work is credited with a decrease in shootings — have had a significant impact.

“We are extremely pleased with where we are with violent crime at this point in the year, but there is still a lot of work to be done,” Police Chief Bill Scott said in an interview at department headquarters. “There’s no magic formula, but what we try to do is implement strategies.”

As of late Saturday, when a man was shot to death in the Excelsior neighborhood, San Francisco had recorded 44 homicides — a 21 percent dip from the last year, when there were 56 killings. If the number holds through the end of the year, 2018 will see the lowest number of homicides since 1963, according to data provided by the state Department of Justice and reports in The Chronicle’s archive.

“I am glad that we are in a better place this year than last year, and, of course, I want those numbers to improve,” Mayor London Breed said. “I’m excited that violence is dropping in our city. I think it has a lot to do with us having more beat officers and that we are working hard to develop better relationships with the community to prevent things from happening in the first place.”

In its darker days, the city had runs of years with killings in the triple digits. In 1977, when the city’s population was 20 percent lower than today, there were 142 homicides. As recently as 2007, San Francisco had 100 killings.

This year’s drop in homicides corresponds with declining gun violence in the city. As of Dec. 10, shooting deaths were down 41 percent, nonfatal shootings were down 28 percent, and gun violence overall was down 30 percent from the same period last year, according to Police Department figures.

Officials attribute the decline in part to a new gun unit they established in November 2017. The Crime Gun Investigations Center is made up of half a dozen officers, including a lieutenant and investigators, along with an agent and analyst from the federal Bureau of Alcohol, Tobacco, Firearms and Explosives.

The unit collects guns, spent shell casings and bullets and enters them into the National Integrated Ballistic Information Network, which shares digital images of the ballistic evidence across jurisdictions. Investigators use the shared information to develop leads and determine whether a gun was used in other crimes.

“Typically, a lot of agencies don’t test casings when there’s not a victim,” Scott said. “What’s important with our policies is all casings are entered. You might have indiscriminate shooting in the air. The casing might connect to a casing that was used in a murder. So, it helps us close the gap on the investigations.”

Helping investigators is the city’s gunfire detection system, ShotSpotter, which can now alert officers of shootings through an app on their phones, giving them a map of the location.

The U.S. Department of Justice recently awarded the Police Department an $800,000 grant for its gun unit. The Board of Supervisors must sign off on the money.

The new unit has proved effective, officials said, but it’s just one of several strategic initiatives Scott has rolled out since being named chief at the beginning of 2017. In September of that year, he announced a staff shakeup, breaking up some investigative units and doubling the number of officers walking neighborhood beats.

A recent study showed the move helped decrease the number of auto break-ins and assaults in San Francisco, but officials also credit it with helping solve more violent crimes.

“When we pushed some investigators from the Patrol Bureau Task Force and narcotics back onto foot patrols, we sent some very experienced officers back into the community and into uniform,” said Cmdr. Greg McEachern, who heads investigations at the department. “Not only did it give us additional resources out there, but it gave us additional expertise. We saw the communication between the district stations and the investigations units really improve.”

The increase in foot patrols has also helped the city improve community policing efforts, which strengthen ties with residents and increase cooperation from witnesses.

“Part of my plan as mayor is to make sure officers are out there making good relationships and attending events in the community,” Breed said. “That’s how we get to a place where people develop trust and respect, so our communities are safer.”

Moreover, the department has expanded its efforts to work more closely with other law enforcement agencies and community organizations. Among the most successful collaborations has been with the district attorney’s office, which oversees the Crime Strategies Unit.

The unit places prosecutors in city police stations to work with crime analysts and identify trends that help police build stronger cases before trial.

“We’ve seen cases they put together, and they’re really incredible,” District Attorney George Gascón said in a recent interview at Dolores Park in the Mission District.

The park is a popular hangout for families and young people, but it wasn’t always so welcoming. For years it was the scene of shootings between rival gangs as homicides around the city spiraled out of control. Part of the trouble was that the Police Department wasn’t solving many cases, Gascón said.

In the late 1990s, San Francisco had the lowest clearance rate of the 20 largest cities in the country. On average, just 28 percent of violent crimes were solved, according to a Chronicle analysis at the time.

“When we solve a case, we garner more trust,” Scott said. “It gets to whether people have confidence, not only in the Police Department, but the criminal justice system.”

Of the 44 killings in San Francisco so far this year, 29 cases have been cleared and 25 have resulted in arrests. But the overall homicide clearance rate, which compares the number of killings to the number of cases solved, including those from previous years, is around 100 percent, police said.

Gascón acknowledged it would be “disingenuous” to think all of the reductions in crime are related to law enforcement. His philosophy has evolved as he’s moved from being San Francisco’s police chief to its top prosecutor.

He’s often cited as one of the most progressive district attorneys in the country after pushing for numerous statewide criminal justice reforms that have drawn criticism from tough-on-crime groups. But Gascón says big-picture reforms ultimately help people stay out of the system.

“We’re not just simply locking people up,” he said. “We’re being more thoughtful about the people we lock up. The people who need an opportunity are being given another opportunity, and I think that has an impact in reducing recidivism.”

Evan Sernoffsky is a San Francisco Chronicle staff writer. Email: esernoffsky@sfchronicle.com Twitter: @EvanSernoffsky