WASHINGTON — For more than two years, President Trump has repeatedly attacked the Russia investigation, portraying it as a hoax and illegal even months after the special counsel closed it. Now, Mr. Trump’s own Justice Department has opened a criminal investigation into how it all began.

Justice Department officials have shifted an administrative review of the Russia investigation closely overseen by Attorney General William P. Barr to a criminal inquiry, according to two people familiar with the matter. The move gives the prosecutor running it, John H. Durham, the power to subpoena for witness testimony and documents, to impanel a grand jury and to file criminal charges.

The opening of a criminal investigation is likely to raise alarms that Mr. Trump is using the Justice Department to go after his perceived enemies. Mr. Trump fired James B. Comey, the F.B.I. director under whose watch agents opened the Russia inquiry, and has long assailed other top former law enforcement and intelligence officials as partisans who sought to block his election.

Mr. Trump has made clear that he sees the typically independent Justice Department as a tool to be wielded against his political enemies. That view factors into the impeachment investigation against him, as does his long obsession with the origins of the Russia inquiry. House Democrats are examining in part whether his pressure on Ukraine to open investigations into theories about the 2016 election constituted an abuse of power.