WASHINGTON (Reuters) - A Pennsylvania man was sentenced to eight months of house arrest on Tuesday for brandishing a gun near the White House in May before a Secret Service guard shot him, prosecutors said.

Jesse Olivieri, 31, of Ashland, Pennsylvania, was sentenced by U.S. District Court Senior Judge Royce Lamberth and credited with time he has been in custody, the U.S. Attorney's Office said in a statement.

Olivieri will serve his sentence in a hospital, where he is recovering from his gunshot wound, the statement said. After his detention, Olivieri will face three years of supervised release.

Olivieri went through a White House security gate on May 20 openly carrying a loaded .22-caliber handgun. A guard shot him once when he ignored commands to stop and drop the weapon.

Officers found ammunition, an empty holster and a canister of pepper spray in Olivieri's car, which was parked near the White House. A spent .22-caliber shell casing was found near the car.

Olivieri pleaded guilty in September to resisting officers with a dangerous weapon.

President Barack Obama was not at the White House when the incident occurred, but it prompted a lockdown of the complex.

(Reporting by Ian Simpson; Editing by Cynthia Osterman)