A man who walked into a crowded Costco Wholesale store in a Kansas City suburb brandishing a gun was shot and killed by an off-duty police officer Sunday, officials said.

At about 11 a.m., the gun-toting man entered the store in Lenexa, Kan., located about 14 miles southwest of downtown Kansas City, police said.

Ryan Vacca told FOX 4 Kansas City he was working at the Costco photo center when he heard "some commotion."

"I turned and looked at the front door and saw a guy walking in - just kind of yelling and screaming," Vacca said. "One of my co-workers told me to drop, and I did."

Lenexa Police Capt. Wade Borchers told FOX 4 the off-duty police officer happened to be at the store, and immediately jumped in to subdue the man as shoppers fled toward exits.

"He was just shopping, and he happened to be there while all this occurred. And you know, thankfully, he was," Borchers said.

MISSOURI HOMEOWNER SHOOTS, KILLS SUSPECT DURING HOME INVASION

Authorities have not released the names of the suspect or officer.

Some people who had to be treated for panic attacks but there were no other injuries, police told FOX 4.

Shopper Nikki Lotia told FOX 4 she heard four shots, and ran to hide in the store's pharmacy area.

"It was very scary," she said. "That 45 minutes of my life. All of the time I was thinking, 'this might be my last day.'"

Lotia said she's grateful that off-duty officer just happened to be shopping at Costco early Sunday.