WASHINGTON — A former State Department diplomatic security officer and military contractor was charged with conducting espionage for China after F.B.I. agents found top-secret documents and apparently incriminating messages on a communications device he brought back from Shanghai, the Justice Department said on Thursday.

The man, Kevin Patrick Mallory, 60, of Leesburg, Va., made his initial appearance in Federal District Court in Alexandria, the department said. He is also charged with lying to federal investigators.

“The conduct alleged in this complaint is serious, and these charges should send a message to anyone who would consider violating the public’s trust and compromising our national security by disclosing classified information,” Dana J. Boente, the acting assistant attorney general for national security and United States attorney for the Eastern District of Virginia, said in a statement.

Geremy C. Kamens, a federal public defender identified on the docket as representing Mr. Mallory, did not respond to an email inquiry.