Montgomery County police are investigating a possible connection between this week’s slaying of a man walking home from work and last week’s killing of a man inside his home, which both occurred in the relatively peaceful community of Olney, officials said Tuesday.

Both men were shot. Police were comparing ballistic evidence from both scenes but by late Tuesday had not determined whether the shots were fired by the same gun.

Punyasara W. Palkumbure Gedara, 41, a native of Sri Lanka, was shot Monday afternoon while walking home from his job at a Subway sandwich shop. The other victim, Nazir Ahmed, 81, who was from Pakistan, was found dead inside his home Friday. He was last seen Wednesday night at the Muslim Community Center eight miles away.

“We’re working this with a sense of urgency,” Montgomery Police Chief J. Thomas Manger said.

A police spokeswoman said it was “much too early” to know whether any specific motive linked the killings.

Detectives were searching for an older-model, beige Toyota Camry seen on High Street , traveling toward Georgia Avenue, near Monday’s shooting.

The fact that homicides are so rare in Olney — a bedroom community about 10 miles north of the Capital Beltway — led police to search for a connection between the shootings, said Lucille Baur, a police spokeswoman.

Sometime before 4:20 p.m. Monday, Gedara started walking home from the Subway shop in a shopping center near the intersection of Georgia and Olney Laytonsville Road.

An employee at the shop said Tuesday that Gedara had worked there for less than two weeks. Gedara “just walked in and had a sandwich and applied” for a job, said the employee, who spoke on the condition of anonymity because he was concerned for his safety. He said police had reviewed surveillance video of the store.

It’s only about a six-block walk to Gedara’s home on Bantry Way. Neighbors said they heard several shots.

“It was spooky,” said Seth Fangboner, 33 who was in his home on North High Street when he heard three pops, a pause and a fourth pop. “You don’t really hear that stuff around here.”

Fangboner said that within minutes, he heard a woman wailing, and he looked outside to see neighbors and others rushing down his street toward the victim.

“All I know is that he was just walking home and it was just a random act of violence,” said Darshan Aspanthiya, Gedara’s cousin.

Family members said he had no obvious enemies and that they had no idea why he was attacked.

Gedara was taking classes at Montgomery College, his cousin said, adding that Gedara was married and had no children.

“We just want to find out why,” he added.

Aspanthiya said family members did not know the other victim, Ahmed.

At 5:06 p.m. Friday, police were called to Ahmed’s house in the 19500 block of Olney Mill Road, where he had lived for more than 30 years, officials said.

A friend of Ahmed’s from the Muslim Community Center, on New Hampshire Avenue, had grown concerned, went to check on him and then called police, officials said.

Ahmed regularly attended prayer services at the center and was last seen there two days earlier, on March 16.

Ahmed, neighbors said, lived alone in the home. He was particularly outgoing for his age: He could frequently be spotted walking around his quiet neighborhood or mowing his grass, neighbors said.

Ahmed centered his social life around the nearby Muslim center, said neighbor Jeanne Lange.

He often left his garage door open and doors unlocked — not uncommon in a neighborhood most considered to be safe.

Since the killing, Lange said she had been taking special precautions to lock her own doors at night.

Police ask anyone with information about either case to call detectives at 240-773-5070. Anonymous callers can contact Crime Solvers of Montgomery County at 1-866-411-TIPS (8477) or 240-773-TIPS (8477).