By Scott Malone and Elizabeth Barber

BOSTON (Reuters) - A Massachusetts man slain by law enforcement officers on Tuesday had discussed plans to behead police officers with an associate arrested the same day, according to papers filed in Boston federal court on Wednesday.

Usaamah Abdullah Rahim, 26, who law enforcement officers shot to death after he allegedly confronted them with a large knife, had told David Wright "I'm just going to, ah, go after them, those boys in blue," an FBI agent involved in the investigation said in an affidavit.

Rahim had ordered three knives, with blades ranging in length from 8 inches (20 cm) to 9.75 inches (25 cm), from online retailers and had joked in wire-tapped phone conversations with Wright, 24, about "thinking with your head on your chest," according to the affidavit.

Federal Bureau of Investigation Special Agent Joseph Galietta described that as "a reference to the practice of some foreign terrorist organizations to behead targets and place their heads on their chests in propaganda videos."

The Islamic State group, based in Syria and Iraq, over the past year has released multiple videos depicting the apparent beheadings of captives, including several foreign journalists.

Law enforcement in Boston has been on high alert since a pair of ethnic Chechen brothers killed three people and injured 264 others with a pair of homemade pressure-cooker bombs at the 2013 Boston Marathon. The surviving brother, Dzhokhar Tsarnaev, was convicted of that attack and sentenced to death.

DEFENSE URGES TRANSPARENCY

Wright, who was arrested late Tuesday in the Boston suburb of Everett, advised Rahim to destroy his computer and smartphone to ensure there was no record of the plot, the affidavit said.

Wright, who stands 6 feet, 7 inches (2 meters) tall and was dressed in a black T-shirt, sat quietly as Magistrate Judge M. Page Kelley informed him he had been charged with conspiracy to obstruct justice, which carries a possible five-year prison sentence. Wright did not enter a plea.

Kelley ordered Wright into the custody of the U.S. Marshals Service ahead of a June 19 detention and probable cause hearing.

"I would urge the government, the FBI and law enforcement in investigating this case and related cases to be as transparent as possible and, in enforcing the law, to abide by the law," Wright's attorney Jessica Hedges said after his court appearance. "We have serious concerns about that already."

TWENTY-FOUR-HOUR SURVEILLANCE

Rahim had been under 24-hour surveillance by the Joint Terrorism Task Force, officials said.

Michael Steinbach, assistant director of the FBI's counterterrorism division, discussed the investigation at a Congressional hearing on Wednesday, saying:

"We know ISIL has put out a message to attack the West, specifically law enforcement, military," referring to Islamic State.

Rahim had planned to travel out of state with an unnamed partner for his attack but early on Tuesday told Wright he had changed his mind and would attack police officers in Massachusetts, according to the affidavit.

Boston Police Commissioner William Evans told reporters that when police officers and FBI agents approached Rahim in a parking lot near his job on Tuesday morning to question him, Rahim pulled out a large knife and advanced on them.

When officers told him to drop the weapon, Rahim replied, "you drop yours," according to the affidavit.

Evans, local FBI officials and prosecutors met on Wednesday with leaders of the neighborhood where the shooting occurred to show them video of the incident.

"The individual was not shot in the back and the information that was reported by others that this was the case is inaccurate," said Darnell Williams, chief executive of the Urban League of Eastern Massachusetts, after the meeting.

The video was not released publicly.

The apparently foiled attack came six months after two New York City police officers were shot dead in their patrol car in retribution for police killings of unarmed black men.

(Additional reporting by Patricia Zengerle in Washington; Editing by James Dalgleish)