An Alexandria police officer was shot in Old Town on Wednesday afternoon, just steps from an elementary school where first-graders were outside playing, authorities said.

The officer, 17-year veteran Peter Laboy, 45, was in critical condition Wednesday night at Washington Hospital Center, where he had undergone surgery.

The suspect, a cabdriver, led police on a chase into Fairfax County moments after the shooting. His yellow minivan taxi crashed, and he was taken into custody.

It was a shocking spasm of noontime violence at Wilkes and St. Asaph streets, four blocks from the lunch rush of King Street’s shops and restaurants. After the pop of a gunshot, teachers at Lyles-Crouch Traditional Academy hustled children, who had been on the school’s playground during recess, into the building. The school then remained on lockdown as police and emergency crews flooded the nearby streets and a helicopter landed on the school’s ballfield to take Laboy to the hospital.

“They told us we were not going outside because there was a bad accident,” said Jackson Merrill, a second-grader at the school who was inside when the shooting happened. “Then we got a paper that said a police officer was shot. I felt scared.”

Officer Peter Laboy, 45, a 17-year police veteran, was in critical condition at Washington Hospital Center on Wednesday after he was shot in the head during a traffic stop. (Courtesy of Alexandria Police Department)

Authorities said the cabdriver, whom they identified as Kashif Bashir, 27, of Woodbridge, came to the attention of police Tuesday after women working at a boutique off King Street complained that he had made them uncomfortable in the store. The man was getting too physically close to employees, they told a nearby shop owner.

The cabdriver arrived at the store again late Wednesday morning. After he left, employees called police and told the responding officers which direction they saw him go, authorities said.

Laboy, a motorcycle officer, found the cab several blocks away, near the elementary school, police said. It was unclear what kind of exchange the two men had, but police say the cabdriver shot Laboy once in the head.

As the man drove off, a lookout was issued for the minivan taxi, police said.

When a patrol officer spotted the cab and tried to stop it, the driver sped away, police said.

With officers in pursuit, Bashir crashed on Fort Hunt Road near Belle View Boulevard and was taken into custody, police said. He has been charged with malicious wounding of a law enforcement officer and use of a firearm in the commission of a felony.

On Wednesday night at Washington Hospital Center, Alexandria Police Chief Earl L. Cook said investigators were working to piece together the events leading to the shooting. “It will take days, if not weeks, for us to put together what happened in this horrific incident,” he said.

Cook said Laboy, whom he described as a “cop’s cop,” is married, has children and volunteers in city schools.

“I’ve known Peter for a long time and words cannot express how we feel about this horrific event,” Cook said. “Our prayers go out to Peter and his family as he struggles to regain his life.”

The shooting also left parents at Lyles-Crouch upset and confused. Police initially said a police officer had been struck by a car. But at 1:15 p.m., the school sent an e-mail to parents saying two shots had been fired and an officer had been hit.

Judy Merrill said she had not yet heard what had happened when she drove by the school and saw police cars and fire engines.

“I completely freaked out and started crying,” said Merrill, who has a kindergartner and a second-grader at the school. “Your first thought is a school shooting. It’s sad your mind goes there.”

After the shooting, the school went on “lock in” mode, according to a letter sent to parents from Principal Patricia Zissios. The rest of the school day progressed, but students were not allowed outside.

Parents got a more detailed picture of what happened through e-mail updates from the PTA president and the principal and from posts on a school Facebook page. One parent posted that after the shooting, as the children were being rushed inside, a teacher picked up a first-grader on crutches and ran with him toward the building.

Angela Rice said she went to the school about noon to drop off a flute for her fourth-grade daughter. She saw ambulances and police cars pulling up, and watched as the helicopter landed in the schoolyard. Another mother told her that she had heard gun­shots. The principal greeted her at the door, she said, and was very calm and “professional” and made her feel as if things were under control inside the school.

Heather Cirmo, who has a first-grader at the school, said that she was pleased with the school’s response and that the school community is very tightknit. But she said she was alarmed at what happened. Her son was in the cafeteria during the shooting.

“A stray bullet easily could have gone into the playground,” Cirmo said. “We’re all thinking about the officer who was shot.”

Parent Angie Gunning, who also has two children at the school, added: “Why was there a loaded gun close to our kids?”

Linus Liddle, who lives across the street from the school, said he was in his house when he heard a single gunshot.

“It’s surprising something like this happened here,” said Liddle, who moved to his house with his wife in 1974. “There’s not been a shooting since we’ve been here.”

The last Alexandria officer who was shot in the line of duty was Kyle Russel, who was wounded during a traffic stop in September 2008. His bullet-resistant vest stopped the bullet. The last Alexandria officer to die in the line of duty was Charlie Hill, who was shot in 1989.

Patricia Sullivan and Clarence Williams contributed to this report.