A onetime White House lawyer under President Donald J. Trump warned him late last year that Mr. Trump could face legal liability if he did not return government materials he had taken with him when he left office, three people familiar with the matter said.

The lawyer, Eric Herschmann, sought to impress upon Mr. Trump the seriousness of the issue and the potential for investigations and legal exposure if he did not return the documents, particularly any classified material, the people said.

The account of the conversation is the latest evidence that Mr. Trump had been informed of the legal perils of holding onto material that is now at the heart of a Justice Department criminal investigation into his handling of the documents and the possibility that he or his aides engaged in obstruction.

In January, not long after the discussion with Mr. Herschmann, Mr. Trump turned over to the National Archives 15 boxes of material he had taken with him from the White House. Those boxes turned out to contain 184 classified documents, the Justice Department has said.

But Mr. Trump continued to hold onto a considerable cache of other documents, including some with the highest security classification, until returning some under subpoena in June and having even more seized in a court-authorized search of his Mar-a-Lago residence and private club by F.B.I. agents last month.

The precise date of the late 2021 meeting between Mr. Trump and Mr. Herschmann is unclear. It was also unclear what, if any, awareness Mr. Herschmann had of what was in the boxes.

But by then, the National Archives had told associates of Mr. Trump that it was missing documents like original copies of his presidential correspondence with the North Korean dictator Kim Jong-un and the letter left for him by President Barack Obama. Archives officials said they had been told by then that there were roughly two dozen boxes of documents that had been in the White House residence and which qualified as presidential records, which had never been sent to the archives.

By the time of the meeting, Mr. Herschmann, a former prosecutor, was not working with or for Mr. Trump, from whom the National Archives had spent months trying to procure missing material.

Mr. Trump thanked Mr. Herschmann for the discussion but was noncommittal about his plans for returning the documents, the people familiar with the conversation said.

Mr. Herschmann, who defended Mr. Trump during his first impeachment trial but tried to stop several efforts by outside advisers aimed at keeping him in power after he lost the 2020 election, declined to comment. A spokesman for Mr. Trump did not immediately respond to a request for comment.

The meeting between Mr. Herschmann and Mr. Trump has not been previously reported, and it adds to the picture of Mr. Trump’s interactions with several people about returning the documents in the months before the National Archives retrieved 15 boxes of material in January of this year. When they went through the boxes, officials at the archives discovered that they contained nearly 200 individual classified documents.

Some of Mr. Trump’s advisers, including informal ones such as Tom Fitton, of the conservative legal advocacy group Judicial Watch, have told the former president that he could hold onto the documents as personal records, according to people briefed on their discussions.

Mr. Trump is facing not just the investigation over potential mishandling of government records, but also a number of other inquiries, including a wide-ranging Justice Department investigation into what led to the Jan. 6, 2021, attack on the Capitol and a state investigation in Georgia into efforts to overturn the outcome of the 2020 election.

Lawyers for Mr. Trump turned over an additional set of classified documents in June. The F.B.I. then carried out a search warrant at Mar-a-Lago on Aug. 8 and retrieved more than 100 additional individual documents with classified markings.

A federal judge in Florida has at least temporarily barred the Justice Department from using the material seized in the search in pursuing its criminal investigation. On Friday, the department asked a federal appeals court to let the F.B.I. regain access to those 100 or so sensitive documents so it could continue the inquiry and assess the national security risks stemming from Mr. Trump keeping them in an unsecured location.

The special master appointed to determine whether the material seized in the search is subject to attorney-client privilege or executive privilege is scheduled to meet with lawyers for Mr. Trump and the Justice Department on Tuesday.