The Secret Service, which protects the president and his family, briefly locked down the White House as a precaution, and Vice President Joe Biden was secured within the White House complex during the lockdown, a White House spokeswoman said.
The shooting took place just off 17th and E streets, near what is known as the South Lawn outside the home and offices of the president.
A man carrying a gun approached a checkpoint shortly after 3 p.m. when uniformed Secret Service officers ordered him to stop and drop the weapon, 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," the statement said.The man was taken to hospital in critical condition, the District of Columbia Fire and Emergency Medical Services Department said.
A man who appeared to be in his mid-20s walked to a gate of the White House holding a silver-colored gun pointed at the ground, said Brett Polivka, a 26-year-old visitor from Texas who was near the south side of the White House.
"A couple officers drew their guns, went right at him and within two or three seconds we heard a gunshot," Polivka said.
The Secret Service, which also guards other top dignitaries, said all those under its protection were safe, but it did not say if Obama's family was home at the time.
"Everyone in the White House is safe and accounted for," a White House official said.
The shooting followed several incidents that raised questions about the Secret Service's performance.
In September 2014, a knife-carrying man jumped a fence and ran into the White House itself in one of the worst security breaches during Obama's tenure.
That episode led to the resignation of the Secret Service's director.
In March 2015, two Secret Service agents capped off a night of drinking by driving into a White House barricade inches away from a suspicious package that investigators were examining.
In 2011, a man hit the White House with automatic rifle fire, though damage to the building was not discovered for several days