WASHINGTON — The F.B.I. director, James B. Comey, told his top agents from around the country that he had been asked by President Trump to stay on the job running the federal government’s top law enforcement agency, according to people familiar with the matter.

A decision to retain Mr. Comey would spare the president another potentially bruising confirmation battle. It would also keep Mr. Comey at the center of the F.B.I.’s investigation into several Trump associates and their potential ties with the Russian government.

Retaining Mr. Comey could also help calm the bureau’s work force, which has been rattled after a tumultuous few months in which the F.B.I. and the director himself were sharply criticized for moves that many felt influenced the outcome of the presidential election.

During the campaign, Mr. Trump harshly criticized the F.B.I. and the Justice Department for not bringing criminal charges against Hillary Clinton in connection with her use of a personal email server. After Mr. Trump was elected in November, he said in a nationally televised interview that he had not made up his mind about whether he would ask Mr. Comey to resign.