A man who allegedly shot and critically injured a San Francisco police officer before being fatally shot himself by police was identified Monday as a 26-year-old Pacifica resident.

Nicholas McWherter died at San Francisco General Hospital on Sunday, according to the city medical examiner’s office.

He was shot by police, officials said, about an hour after he opened fire on officers on Everglade Drive near the Lakeshore Plaza Shopping Center at about 8:15 p.m. Friday, striking Officer Kevin Downs in the head.

The officers had been responding to reports of a man acting erratically and threatening others, and initially did not know he was armed.

McWherter fled across Sloat Boulevard toward Stern Grove, but eventually emerged from bushes at 28th Avenue and Vicente Street, still armed, officials said.

Despite orders to drop the weapon, he continued to hold the gun to his chest, police said, and officers shot him during the confrontation.

McWherter still refused to surrender, but officers reported that they were able to take him into custody after they deployed flash-bang stun grenades and distracted him.

“They did everything they could to make sure that at least the subject had a fighting chance,” said interim Police Chief Toney Chaplin.

Little is known about McWherter, and efforts to reach his family Monday were unsuccessful.

Downs, who remained hospitalized Monday, is expected to survive. Police officials said he underwent surgery to remove bullet fragments from his brain, and was partially paralyzed on one side of his body.

Chaplin said that if the bullet had struck him “1 centimeter down,” the wound might have been lethal.

Downs, an officer out of Taraval Station on 24th Avenue, is in his early 20s and has been on the force for two years.

He co-founded an organization called Ranchin’ Vets, which helps veterans who served after 9/11. The organization partners with ranches and farms from across the country to create opportunities in the agricultural industry for veterans and helps them in their transition from military to civilian life.

Downs, who attended Mount St. Mary’s University in Maryland, had spent summers working on a ranch in Marin County, according to the Ranchin’ Vets website.

Downs, whose brother was in the Marine Corps, saw the “struggles and lack of employment opportunities our veterans faced as they transition back into civilian life” and decided to start the organization.

The last San Francisco police officer shot in the line of duty had been Bryan Tuvera, who died from his injuries on Dec. 23, 2006.

Friday’s incident marked the Police Department’s first fatal shooting by officers since the May 19 death of Jessica Williams, who was shot while driving an allegedly stolen car in the Bayview neighborhood. Williams was unarmed, and the incident prompted then-Chief Greg Suhr’s resignation.

Chaplin said the department was working to organize a town hall meeting this week to talk about the McWherter shooting, despite his earlier decision to discontinue the practice.

Vivian Ho is a San Francisco Chronicle staff writer. Email: vho@sfchronicle.com Twitter: @VivianHo