(CNN) Attorney General William Barr on Thursday rebuked President Donald Trump for publicly commenting on sensitive investigations but insisted the Justice Department had acted appropriately after an extraordinary falling out with career prosecutors who had handled the case of Roger Stone earlier this week.

In an interview with ABC News, Barr provided a robust defense of the department's rank-and-file and said Trump's online missives made it "impossible" to do his job.

"I cannot do my job here at the department with a constant background commentary that undercuts me," Barr said.

"To have public statements and tweets made about the department, about people in the department, our men and women here, about cases pending in the department and about judges before whom we have cases, make it impossible for me to do my job and to assure the courts and the prosecutors in the department that we're doing our work with integrity," he said.

The criticism was a notable zag for Barr after days of mounting scrutiny over his role in the fraught decision to publicly disavow prosecutors who had sought a stiff punishment for Stone, a longtime friend of Trump. The President had tweeted congratulations Barr for the move, provoking outcry from Democrats who demanded an investigation.

The four career attorneys who had worked on the Stone case and signed off on the original sentencing memorandum each withdrew from the case on Tuesday in an apparent protest. In the interview Thursday, Barr explained the discrepancy at the heart of the public spat this week over the Stone sentencing and blamed a late night tweet from the President for creating the environment that evoked outrage from the left.

Barr pinned the mix-up on a miscommunication between him and the interim head of the DC US attorney's office, Tim Shea, who had been a close aide of Barr's until earlier this month.

Barr said that Shea spoke briefly with him in person on Monday and had explained that the prosecutors handling the case had wanted to pursue the elevated sentence of seven to nine years, "but he thought that there was a way of satisfying everybody and providing more flexibility."

The filing that eventually made it before a judge and the public on Monday night was not what Barr was expecting. He was "very surprised," and told his staff to prepare to amend the filing in the morning. But then Trump tweeted, slamming the prosecutors in a middle of the night post.

That tweet, Barr said, forced him to reevaluate if he would still be able to make the change to soften the sentencing request.

"I had made a decision that I thought was fair and reasonable in this particular case, and once the tweet occurred the question is: Well, now what do I do? Do you go forward with what you think is the right decision or do you pull back because of the tweet? And that just sort illustrates how disruptive these tweets can be."

Barr said he was "a little surprised" that the prosecutors had stepped down, and told ABC News that it was "preposterous" to characterize his role in the developments this week as an intervention. He argued he had merely acted to resolve an internal department dispute.

He has not spoken with the prosecutors, he added.

Barr said Trump has never made any requests to him about criminal cases, including the Stone sentencing, and pledged that he wouldn't carry out an order from the President to investigate a political opponent.

"If he were to say, 'Go investigate somebody,' and you sense it's because they're a political opponent, then an attorney general shouldn't carry that out, wouldn't carry that out," Barr said.

He also admitted that the President's public commentary on Department of Justice criminal cases feed a narrative that he is not an independent attorney general.

"The fact that the tweets are out there and correspond to things we're doing at the department sort of give grist to the mill, and that's why I think it's time to stop the tweeting about Department of Justice criminal cases," Barr said.

Barr told ABC that he hoped the President would react and respect the criticism of his tweets delivered in the interview.

"I hope he will react," Barr said.

A White House official said Trump is not upset with Barr after his comments to ABC. The New York Times reported that Barr had let Trump know some of what he planned to say ahead of the interview.

"The President wasn't bothered by the comments at all and he has the right, just like any American citizen, to publicly offer his opinions," said White House press secretary Stephanie Grisham in a statement. "The President has full faith and confidence in Attorney General Barr to do his job and uphold the law."

Earlier this week, Trump insulted the career Justice Department attorneys who handled the Stone case, saying they had been "exposed for recommending a ridiculous 9 year prison sentence" and insinuating that they were "Mueller people."

Two of the attorneys had worked under former special counsel Robert Mueller, while the other two had picked up the case when it was transferred to the DC US attorney's office.

The interview, Barr's first public remarks since the episode, came as Shea was also playing cleanup and working to restore confidence among his staff. In an email Wednesday night that was reviewed by CNN, Shea commended his workforce and pledged to support the work of the office.

He added that some of the scrutiny over the Stone filings was "uninformed and unfounded," and that he was planning to meet with staff later in the week to discuss the matter further.

People familiar with the situation at the office described prosecutors who were shocked and concerned by the Justice Department's leadership, with some speculation about more resignations taking place.

This story has been updated with additional comments from the interview.