A man approached a White House security checkpoint with a gun Friday afternoon and was shot by a Secret Service agent when he refused to put down the weapon, authorities said.

The White House was locked down for about an hour. Everyone under the protection of the Secret Service is safe, the agency said.

The shooting occurred within view of sightseers outside the White House, near sidewalks crowded with families, school groups and government workers.

The man with the gun approached a Secret Service guard post at 17th and E streets NW, just west of the White House compound, about 3 p.m., a Secret Service spokesman said.

The man refused to put down the gun and was shot by a Secret Service agent.

Law enforcement officials identified the man as Jesse Olivieri from Ashland, Pennsylvania, NBC News reports.

"Secret Service Uniformed Division Officers gave numerous verbal commands for the subject to stop and drop the firearm," the agency said in a statement. "When the subject failed to comply with the verbal commands, he was shot once by a Secret Service agent and taken into custody."

Olivieri is in critical condition and was rushed to George Washington University Hospital, a D.C. Fire and EMS representative said.

The suspect's gun was recovered at the scene, officials said.

Olivieri is believed to have wanted to commit "suicide by cop" and be killed by an officer, law enforcement sources told NBC News.

Witness Larry Samples told News4 he saw a man with a silver gun walk toward the White House. Secret Service agents repeatedly ordered him to stop and drop the weapon, but he ignored them, Samples said. A Secret Service agent then shot the man.

"They gave him multiple chances to stop his advance," Samples said.

Witness Taylor Cates said she saw a man with a blank expression walk with a gun in plain sight and then get shot.

Witness Odis Bellinger, who was visiting the White House from Detroit, said he was near a security checkpoint when he heard three shots and was told to run.

“I’m from Detroit and we don’t even see that there," Bellinger said.

Lamman Rucker, a D.C. native and actor who appeared in the movie "Why Did I Get Married?" was lined up to enter the White House when he heard shots.

"Literally out of nowhere, you’ve got different officers and different agencies that just ascended upon that entry point with the quickest of speed," he said.

Nearby, on Constitution Avenue NW, D.C. police searched a white sedan with a Pennsylvania license plate. Police are determining whether the car is a threat.

President Barack Obama departed the White House about 1 p.m. for a golf outing at Joint Base Andrews in Maryland, according to White House pool reports. His motorcade arrived there about 1:30 p.m.

Vice President Joe Biden was inside the building, according to multiple reports.

First lady Michelle Obama was wrapping up a speech in downtown Washington at midday Friday. Her office would not say whether she, or the Obama daughters, were at the White House at the time.

Reporters in the White House said on Twitter they were ordered to shelter in place in the basement of the building.

"At this time, based on a preliminary investigation, there is no known nexus to terrorism. However, an investigation continues into the motives behind his actions," read a joint statement released Friday night by D.C. and federal law enforcement.

D.C. Mayor Muriel Bowser said District officials are coordinating with federal officials.

On March 28, the U.S. Capitol was locked down after a Capitol police officer shot and injured a man who police say brought a BB gun into the building's visitor center. Witnesses described a chaotic scene near the Capitol as tourists and others in the area ran to seek shelter. The suspect was critically injured, and police charged him with assault with a deadly weapon and assault on a police officer while armed.

Stay with News4 and NBCWashington.com for more details on this developing story.