WASHINGTON — A man who approached the White House on Friday brandishing a gun was shot and wounded by a Secret Service agent, the agency’s spokesman said. The man, whose identity was not released, was taken into custody and treated at a nearby hospital.

President Obama was away at the time, playing golf at Andrews Air Force Base in Maryland. He was told about the shooting, a White House official said.

The episode began shortly after 3 p.m. Friday, when the man walked toward a security checkpoint on E Street, southwest of the White House.

“The Secret Service Uniformed Division officers gave numerous verbal commands for the subject to stop and drop the firearm,” David A. Iacovetti, the deputy assistant director of government and public affairs for the Secret Service, 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.”