A Sacramento officer was killed when a gunman opened fire as police attempted to help a woman involved in a dispute Wednesday evening.

An hourslong standoff with the suspected shooter ended Thursday morning when the man surrendered and was arrested, the Sacramento Police Department said in a tweet.

The suspect has not been identified.

Officer Tara O'Sullivan, 26, died at a hospital after being shot while helping a woman who was engaged in a disturbance with a man, police said.

Officer Tara O'Sullivan, right, with graduating class of Law Enforcement Candidate Scholars. Sacramento State

"She gave her young life while protecting our community," police Deputy Chief Dave Peletta said early Thursday at a news conference.

"We are devastated," Sacramento police said on Twitter. "There are no words to convey the depth of the sadness we feel, or how heartbroken we are for the family of our young, brave officer."

Police were initially called to a home around 11:45 a.m. on Wednesday for a disturbance between a man and a woman, the Sacramento Police Department said in a press release on Thursday.

Around 5:30 p.m., officers were called to a different home to assist the woman as she gathered some of her belongings. About 30 minutes later officers at the scene reported shots being fired and said O'Sullivan had been struck, Sacramento police said.

As officers returned fire, the suspect continued to fire using what police believe was a rifle.

Police said Wednesday the suspect was the only one in the home. The woman whom O'Sullivan was helping was able to get out safely, and nearby residents were evacuated, NBC affiliate KCRA of Sacramento reported.

An armored vehicle was called in to rescue O'Sullivan, and transported her to the hospital around 7 p.m.

Peletta said the suspect continued to fire randomly up until 11:30 p.m. A crisis negotiation team that was called in was able to make contact with the gunman, who surrendered just before 2 a.m. Thursday, police said.

It is with a broken heart that we have to share with all of you that earlier today we lost one of our own. While on a call for service in North Sacramento, Officer Tara O’Sullivan was shot and killed. She gave her young life while protecting our community pic.twitter.com/MXr7C4M5qJ — Sacramento Police (@SacPolice) June 20, 2019

Five officers fired their weapons during the standoff, Sacramento police said.

O'Sullivan, who was hired by the department in January 2018 in an administrative capacity, entered the police academy in July and graduated in December. She was partnered with a training officer, said Peletta, who noted that other officers were also on the scene.

Sacramento Mayor Darrell Steinberg said the city is heartbroken over O'Sullivan's death. "To the officers that are still out there, we as a community rally and pray for their safety, because they're still in harm's way," he said.