NEW DELHI — President Trump lashed out at two liberal Supreme Court justices on Tuesday, escalating his battle with the judicial system to new heights despite entreaties by his attorney general to refrain from attacks that complicate the administration’s legal fights.

Weighing in on a domestic matter as he began a day of ceremony, meetings and a joint appearance with Prime Minister Narendra Modi of India, Mr. Trump seized on a dissenting opinion last week by Justice Sonia Sotomayor and a years-old comment by Justice Ruth Bader Ginsburg to demand that the two Democratic-appointed jurists recuse themselves from any cases involving him.

“I just thought it was so inappropriate, such a terrible statement for a Supreme Court justice,” the president said.

Besides ignoring the entreaties of Attorney General William P. Barr, the president’s attack on the two justices also risked provoking a reaction from Chief Justice John G. Roberts Jr. In 2018, Chief Justice Roberts admonished Mr. Trump for calling a federal judge who ruled against one of his administration’s policies, “an Obama judge.”