WASHINGTON — Just weeks before Blackwater guards fatally shot 17 civilians at Baghdad's Nisour Square in 2007, the State Department began investigating the security contractor's operations in Iraq. But the inquiry was abandoned after Blackwater's top manager there issued a threat: "that he could kill" the government's chief investigator and "no one could or would do anything about it as we were in Iraq," according to department reports.

U.S. Embassy officials in Baghdad sided with Blackwater rather than the State Department investigators as a dispute over the probe escalated in August 2007, the previously undisclosed documents show. The officials told the investigators that they had disrupted the embassy's relationship with the security contractor and ordered them to leave the country, according to the reports.

After returning to Washington, the chief investigator wrote a scathing report to State Department officials documenting misconduct by Blackwater employees and warning that lax oversight of the company, which had a contract worth more than $1 billion to protect U.S. diplomats, had created "an environment full of liability and negligence."

"The management structures in place to manage and monitor our contracts in Iraq have become subservient to the contractors themselves," the investigator, Jean C. Richter, wrote in an Aug. 31, 2007, memo to State Department officials. "Blackwater contractors saw themselves as above the law," he said, adding that the "hands off" management resulted in a situation in which "the contractors, instead of Department officials, are in command and in control."

His memo and other newly disclosed State Department documents make clear that the department was alerted to serious problems involving Blackwater and its government overseers before the Nisour Square shooting, which outraged Iraqis and deepened resentment over the United States' presence in the country.

Today, as conflict rages again in Iraq, four Blackwater guards involved in the Nisour Square shooting are on trial in Washington on charges stemming from the episode, the government's second attempt to prosecute the case in a U.S. court after previous charges against five guards were dismissed in 2009.

The shooting was a watershed moment in the U.S. occupation of Iraq, and was a factor in Iraq's refusal the next year to agree to a treaty allowing U.S. troops to stay in the country beyond 2011. Despite a series of investigations in the wake of Nisour Square, the back story of what happened with Blackwater and the embassy in Baghdad before the fateful shooting has never been fully told.

The State Department declined to comment on the aborted investigation. A spokesman for Erik Prince, the founder and former chief executive of Blackwater, who sold the company in 2010, said Prince had never been told about the matter.

After Prince sold the company, the new owners named it Academi. In early June, it merged with Triple Canopy, one of its rivals for government and commercial contracts to provide private security. The new firm is called Constellis Holdings.

Experts who were previously unaware of this episode said it fit into a larger pattern of behavior. "The Blackwater-State Department relationship gave new meaning to the word 'dysfunctional,' " said Peter Singer, a strategist at the New America Foundation, a public policy institute, who has written extensively on private security contractors. "It involved everything from catastrophic failures of supervision to shortchanging broader national security goals at the expense of short-term desires."

Even before Nisour Square, Blackwater's security guards had acquired a reputation among Iraqis and U.S. military personnel for swagger and recklessness, but their complaints about practices ranging from running cars off the road to shooting wildly in the streets and even killing civilians typically did not result in serious action by the United States or the Iraqi government.

But scrutiny of the company intensified after a Blackwater convoy traveling through Nisour Square on Sept. 16, 2007, just over two weeks after Richter sent his memo, fired on the crowded traffic circle. A 9-year-old boy was among the civilians killed. Blackwater guards later claimed that they had been fired upon first, but U.S. military officials who inspected the scene determined that there was no evidence of any insurgent activity in the square that day. Federal prosecutors later said Blackwater personnel had shot indiscriminately with automatic weapons, heavy machine guns and grenade launchers.

Founded in 1997 by Prince, a former member of the Navy SEALs and an heir to an auto parts fortune, Blackwater began as a small company providing shooting ranges and training facilities in rural North Carolina for the military and for police departments. After the U.S.-led invasion of Afghanistan and later Iraq, it ramped up to become a global security contractor with billions of dollars in contracts for the State Department and the Central Intelligence Agency.

The company's gung-ho attitude and willingness to take on risky tasks were seductive to government officials in Washington. The State Department, for example, secretly sent Blackwater guards to Shenyang, China, to provide security for North Korean asylum seekers who had gone to the U.S. Consulate there and refused to leave for fear the Chinese government would force them to go back to North Korea, according to company documents and interviews with former Blackwater personnel.

But Blackwater's rapid growth and the State Department's growing dependence on the contractor led to unbridled hubris, according to several former company officials. That was fostered, they said, by Prince, who not long before the Nisour Square shooting gathered employees in front of Blackwater headquarters in Moyock, N.C., and demanded that they swear an oath of allegiance.

Soon after State Department investigators arrived in Baghdad on Aug. 1, 2007, to begin a monthlong review of Blackwater's operations, the situation became volatile. Internal State Department documents, which were turned over to plaintiffs in a lawsuit against Blackwater that was unrelated to the Nisour Square shooting, provide details of what happened.

It did not take long for the two-man investigative team — Richter, a Diplomatic Security special agent, and Donald Thomas Jr., a State Department management analyst — to discover a long list of contract violations by Blackwater.

They found that Blackwater's staffing of its security details for U.S. diplomats had been changed without State Department approval, reducing guards on many details to eight from 10, the documents said. Blackwater guards were storing automatic weapons and ammunition in their private rooms, where they also were drinking heavily and partying with frequent female visitors. Many of the guards had failed to regularly qualify on their weapons, and were often carrying weapons on which they had never been certified and that they were not authorized to use.

The armored vehicles Blackwater used to protect U.S. diplomats were poorly maintained and deteriorating, and the investigators found that four drunk guards had commandeered one heavily armored, $180,000 vehicle to drive to a private party, and crashed into a concrete barrier.

Blackwater was also overbilling the State Department by manipulating its personnel records, using guards assigned to the State Department contract for other work and falsifying other staffing data on the contract, the investigators concluded.

A Blackwater-affiliated firm was forcing "third country nationals" — low-paid workers from Pakistan, Yemen and other countries, including some who performed guard duty at Blackwater's compound — to live in squalid conditions, sometimes three to a cramped room with no bed, according to the report by the investigators.

The investigators concluded that Blackwater was getting away with such conduct because embassy personnel had gotten too close to the contractor.

On Aug. 20, 2007, Richter was called in to the office of the embassy's regional security officer, Bob Hanni, who said he had received a call asking him to document Richter's "inappropriate behavior." Richter quickly called his supervisor in Washington, who instructed him to take Thomas with him to all remaining meetings in Baghdad, his report noted.

The next day, the two men met with Daniel Carroll, Blackwater's project manager in Iraq, to discuss the investigation, including a complaint over food quality and sanitary conditions at a cafeteria in Blackwater's compound. Carroll barked that Richter could not tell him what to do about his cafeteria, Richter's report said. The Blackwater official went on to threaten the agent and say he would not face any consequences, according to Richter's later account.

Carroll said "that he could kill me at that very moment and no one could or would do anything about it as we were in Iraq," Richter wrote in a memo to senior State Department officials in Washington. He noted that Carroll had formerly served with Navy SEAL Team 6, an elite unit.

"Mr. Carroll's statement was made in a low, even tone of voice, his head was slightly lowered; his eyes were fixed on mine," Richter stated in his memo. "I took Mr. Carroll's threat seriously. We were in a combat zone where things can happen quite unexpectedly, especially when issues involve potentially negative impacts on a lucrative security contract."

He added that he was especially alarmed because Carroll was Blackwater's leader in Iraq, and "organizations take on the attitudes and mannerisms of their leader."

Thomas witnessed the exchange and corroborated Richter's version of events in a separate statement, writing that Carroll's comments were "unprofessional and threatening in nature." He added that others in Baghdad had told the two investigators to be "very careful," considering that their review could jeopardize job security for Blackwater personnel.

Richter was shocked when embassy officials sided with Carroll and ordered Richter and Thomas to leave Iraq immediately, according to the documents. On Aug. 23, Ricardo Colon, the acting regional security officer at the embassy, wrote in an email that Richter and Thomas had become "unsustainably disruptive to day-to-day operations and created an unnecessarily hostile environment for a number of contract personnel." The two men cut short their inquiry and returned to Washington the next day.

Richter and Thomas declined to comment for this article. Carroll did not respond to a request for comment.

On Oct. 5, 2007, just as the State Department and Blackwater were being rocked by scandal in the aftermath of Nisour Square, State Department officials finally responded to Richter's August warning about Blackwater. They took statements from Richter and Thomas about their accusations of a threat by Carroll, but took no further action.