Security at a Brooklyn homeless shelter was so lax a vagrant was able to keep a gun at the facility — and used it to shoot two local men while a guard did nothing to stop him, a lawsuit filed Tuesday alleges.

The suit filed in Brooklyn Supreme Court on Tuesday claims the unnamed guard at the Star Bright Family Residence in Canarsie looked the other way as alleged shooter Mervyn Haynes flashed the weapon while “indicating to the officer that he was going to use the gun” following a dispute with two men outside the shelter in July.

Haynes, 35, then allegedly shot Justin Kelly and Jerome Bethune in the head — killing Kelly and critically wounding Bethune, the suit claims.

“This incident is emblematic of why people throughout the city object to homeless shelters coming up in their neighborhoods,” said Abe George, an attorney for the victims and their families.

George claimed the facility “neglected their own internal safety protocols in allowing people to enter their own facility without proper security screening, thereby creating a danger to the community the shelter was trying to serve.”

The suit — filed on behalf of Bethune and Kelly’s mother, Barbara Mullings — names Haynes, Star Bright and unidentified security guards at the facility.

The shooting happened around 3 a.m. July 10, when Haynes was returning to the non-profit agency’s shelter on 104th Street and got into a heated dispute with Kelly and Bethune outside.

Haynes then stormed inside to get a handgun he kept there — which he was apparently able to get into the facility despite metal detectors and security guards who are supposed to keep weapons out, the suit charges.

Haynes then headed back outside with the gun, passing the guard — and flashing the weapon to him — before shooting the two men, the lawsuit alleges.

Both victims were taken to Brookdale Hospital Medical Center. Kelly, who was shot in the head, died. Bethune, who was hit in the neck and face, was listed in critical condition.

He has since undergone “multiple” surgeries but survived.

Haynes was arrested July 14 and charged with murder and attempted murder and is being held at the Brooklyn Detention Complex without bail.

He has four prior arrests dating to 2000 for assault, menacing with a weapon, sex abuse and criminal possession of a controlled substance, according to the NYPD.

Officials at Star Bright declined to comment Tuesday.

Additional reporting by Daniel Cassady