The shooter in Monday’s Washington Navy Yard rampage had a history of mental illness and was treated at two Department of Veterans Affairs hospitals after saying he was hearing “voices” on a trip to Rhode Island last month, federal law enforcement officials said Tuesday.

Aaron Alexis was having trouble sleeping and was treated at the VA facilities for insomnia, said the officials, who spoke on condition of anonymity as the investigation into the shootings unfolded.

While the motive in Monday’s attack remains unclear, FBI officials said they were examining the mental history of Alexis, who was killed Monday in a gun battle with police after killing at least 12 people at the Navy Yard. Officials at a Rhode Island military base — who received an August report from the Newport Police Department that Alexis was hearing voices — are cooperating in the inquiry, according to Lisa Rama, a public affairs officer at Naval Station Newport.

On Aug. 7, while on a trip to Newport, Alexis called police to his hotel room and told them he was being followed by three people who were keeping him awake “by talking to him and sending vibrations into his body,” according to a police report. The report has the victim’s name blacked out, but Lt. William Fitzgerald of the Newport police confirmed that it was Alexis.

The new revelations came as authorities said Alexis acted alone in the rampage and engaged in a firefight with police that lasted more than 30 minutes. “What caused this individual to kill so many innocent men and women?” Ronald C. Machen Jr., U.S. attorney for the District of Columbia, asked at an afternoon news conference outside the local FBI field office.

Read eyewitness accounts from the Navy Yard shooting.

More details also emerged about Alexis’s highly checkered four-year career as a Navy reservist, a period marked by repeated run-ins with his military superiors and the law, including an incident in which he cursed repeatedly after being thrown out of a nightclub, according to documents and Navy officials.

Alexis was cited at least eight times for misconduct for offenses as minor as a traffic ticket and showing up late for work but also as serious as insubordination and disorderly conduct, said a Navy official, who spoke on condition of anonymity to discuss the gunman’s personnel record.

Alexis did not face court-martial for any of the offenses, which included an insubordination charge in 2008, a disorderly conduct charge in 2009 and extended unauthorized absences from work on multiple occasions between 2008 and 2010. He did receive administrative punishments three times. The official could not detail the punishments, but discipline for such offenses could range from a loss in pay to reduction in rank.

The Navy also gave Alexis an administrative sanction after he was arrested in DeKalb County, Ga., in 2008 and held for two nights in jail, the Navy official said. Alexis was cited for disorderly conduct after he damaged the furniture at a nightclub, was tossed out and began using profanity on the street, according to a police report.

“Would not stop,’’ the responding officer wrote. “Was told several times.’’

Valerie Parlave, assistant director in charge of the FBI’s Washington Field Office, said Alexis arrived in Washington around Aug. 25 and had been staying at local hotels since then, most recently at a Residence Inn in Southwest Washington, beginning Sept. 7. 

Than Su, who works at the Residence Inn gift shop, said nearly 40 FBI agents descended on the hotel starting at about 11 p.m. Monday night. “This is quiet season,” said Su. “But it was not yesterday.”

Earlier Tuesday, the Navy corrected its previous account of the circumstances under which Alexis left the service. He received an honorable discharge, effective Jan. 31, 2011, the Navy official said. On Monday, the Navy mistakenly said he had received a general discharge, a less-desirable category that would have indicated to future employers that there was something amiss with his performance.

The new information added to the emerging portrait of a man with layers of contradictions, who lived for a time in a bungalow in the woods near a Buddhist temple in Fort Worth, where he occasionally joined Thai immigrants in meditation, but was also arrested after firing a bullet through his upstairs neighbor’s floor and was then asked to leave his Fort Worth apartment.

One Navy official, speaking on condition of anonymity, had said Monday that Alexis was discharged in January 2011 for “a pattern of misconduct” and that the 2010 gun incident in Texas played a role in his departure.

But the Navy clarified Tuesday that while the service had originally sought to kick out Alexis with a general discharge, those proceedings were moving slowly, and it was unclear whether the Navy had sufficient cause to push forward. So when Alexis applied on his own to leave the Navy in early 2011 with an honorable discharge, the service granted his request, the official said.

With his honorable discharge, Alexis apparently was issued a government contractor access card that would have allowed him into the Navy Yard and other military installations, said Thomas Hoshko, chief executive of The Experts, a Hewlett-Packard subcontractor for which Alexis was working. His security clearance was updated in July.

“There had to be a thorough investigation,” Hoshko said. “There is nothing that came up in all the searches.”

The honorable discharge could help explain why Alexis, 34, apparently had no difficulty landing a civilian job. He moved from Fort Worth to Washington about a month ago, friends said, and was hired as an hourly tech employee for The Experts, which is updating computer systems at Navy and Marine Corps installations worldwide. He was scheduled to begin work at the Washington Navy Yard this month.

Those who knew Alexis in recent years describe him as a “sweet and intelligent guy” (a regular customer at the Thai restaurant where he had been a waiter) and “a good boy” (his landlord), but also as “very aggressive,” someone who seemed as though he might one day kill himself (a lay worker at the Buddhist temple where Alexis worshiped).

He also had a history of mental issues, authorities said, which apparently emerged during the August trip to Newport.

The police report says that Alexis told police he was a naval contractor and travels often. He said he had been in a “verbal altercation” with somebody on his flight from Virginia to Rhode Island. That unknown person had sent people to follow him, Alexis told police. He had moved from a hotel in Middletown, R.I., to a hotel on a Navy base, but “he heard the same voices talking to him through the walls, floor and ceiling,” the report says.

When Alexis called, he was in his third hotel. But the report said he told police that “the voices were coming through the ceiling,” and that the people were using “ ‘some sort of microwave machine’ to send vibrations through the ceiling, penetrating his body so he cannot fall asleep.”

Alexis also had an angry streak that flared often enough to create an arrest record in three states.

In 2004, Alexis was arrested in Seattle after he fired three shots from a Glock pistol into the tires of a Honda Accord that two construction workers had parked in a driveway adjacent to Alexis’s house. Alexis’s father told detectives then that his son “had experienced anger management problems that the family believed was associated with PTSD,” or post-traumatic stress disorder, according to the police report. The father said Alexis had been “an active participant in rescue attempts of Sept. 11, 2001.”

Alexis’s explanation for his behavior that day: The construction workers had “mocked” and “disrespected” him and then he had “a black-out fueled by anger.”

He was arrested but not charged, Seattle police said. The paperwork apparently was lost.

“That report never got to the Seattle city attorney’s office,” said Kimberly Mills, a spokeswoman for the city attorney. “Consequently, we never filed charges.”

More recently, Alexis struck those who crossed his path as a man of sharp contrasts. He was learning the Thai language, visited Thailand for a month, was studying for an online degree in aeronautical engineering, and enjoyed conversing with diners, according to friends, customers and fellow worshipers. But some said he had an aggressive streak that made them keep their distance and avoid personal questions.

“He’s a 13-year-old stuck in a 34-year-old body,” said Oui Suthamtewakul, owner of the Happy Bowl Thai restaurant in White Settlement, Tex., and a friend who lived with Alexis for most of the past three years. “He needs attention.”

Alexis often worked as an unpaid waiter for Suthamtewakul and his wife, Kristi, but lived with them rent-free. The couple described Alexis as a helpful, chatty guy who liked to watch cooking shows on TV.

“He always hit on girls,” Suthamtewakul said, adding that he had to scold his friend for being too forward with female customers.

Suthamtewakul said Alexis “had a gun at all times” and fired a bullet through the wall of his room in the summer of 2012. “You’re gonna kill me,” the restaurateur told his friend. Alexis apologized and said it was an accident.

Alexis drank alcohol frequently and in large quantities, Suthamtewakul said: “He can start drinking at 9:30 in the morning. He drinks often and for fun, but it was never a problem.” Asked what he will remember about his friend, Suthamtewakul said, “Him with a Heineken.”

Alexis grew up in Brooklyn with his parents, Cathleen and Anthony Alexis, said his aunt Helen Weekes. “We haven’t seen him for years,” she said.

He spent nearly four years in the Navy as a full-time reservist from May 2007 until January 2011, according to the Navy.

Alexis achieved his final rank — aviation electrician’s mate 3rd class — in December 2009.

He spent the bulk of his service time — 2008 to 2011 — assigned to the Fleet Logistics Support Squadron 46 at Naval Air Station Fort Worth, records show. He received the Global War on Terrorism Service Medal and the National Defense Service Medal, awards of minor distinction.

Alexis had finished a contract in Japan for The Experts at the end of 2012, Hoshko said.

“Nobody could have done anything to prevent this except Aaron Alexis,” he said. “Maybe he snapped. I don’t know.”

In Fort Worth, Alexis lived for a time in a gated townhouse community called Orion at Oak Hill. In September 2010, police were called to Apartment 2023 after Alexis’s upstairs neighbor complained that a bullet had been fired through her apartment. Police determined that Alexis had fired a round that went up through her floor and into her ceiling.

The woman told police that Alexis had complained several times that she was too loud. She said he had confronted her a few days earlier in the complex’s parking lot “about making too much noise,” according to a police report.

The woman said that “she is terrified of Aaron and feels that this was done intentionally,” the police report said.

Police tried three times to contact Alexis by knocking on his apartment door, but he didn’t respond. Only after they called in firefighters to force entry did he emerge. He told police that he had been cleaning his gun while cooking and that it accidentally discharged because his hands were greasy, according to the police report.

“He told me that he began to take the gun apart when his hands slipped and pulled the trigger, discharging a round into the ceiling,” the officer wrote. Alexis was arrested for improperly discharging a firearm, but the county district attorney’s office said Monday that there was not enough evidence to pursue the case. Alexis’s mug shot from that arrest shows a clean-shaven man with soft eyes and an impassive expression.

A couple of weeks later, the apartment complex began eviction proceedings against Alexis, according to county records.

Soon after, Somsak Srisan, a Thai immigrant in Fort Worth, met Alexis at the Wat Busayadhammavanaram Meditation Center, where Alexis had occasionally practiced meditation starting in summer 2010. Alexis said he needed a place to stay, and Somsak offered him a two-bedroom white bungalow a short walk away — if he promised not to smoke or drink. Alexis rented the place for $600 a month and never missed a payment, said Somsak, 57.

“He’s a good boy,” said Somsak, speaking halting English. “Everybody would say, ‘He’s a good boy.’ ”

Alexis occasionally meditated at the temple and helped there when needed, said Somsak, who was impressed that his tenant studied Thai and visited Thailand.

On Monday, as word spread about the shootings, the temple filled with members eager to share recollections of Alexis. “They don’t believe it that he could kill 12 people like that,” Somsak said. “I think probably somebody tried to put him down. I don’t know. Did somebody try to discriminate against him?”

Somsak asked Alexis only once why he had left his job at the naval base. It was a brief conversation.

“I asked him, ‘Why you quit the job with the government?’ ” Somsak said. “He said, ‘Somebody doesn’t like me.’ ”

Somsak left it there, he said, because “I don’t want to go too deep with him.”

Alexis visited the center about twice a week and was known as a quiet, if tightly wound, participant, a temple staff member said.

“He would help people if they came in carrying heavy things,” said J. Sirun, an assistant to the monks. “From the outside, he was a quiet person. But on the inside, I think he was very aggressive. He did not like to be close with anybody, like a soldier who has been at war.”

Sirun said he avoided Alexis, who preferred to keep to himself. But Alexis was no loner; he had many Thai friends and spoke Thai “very well,” Sirun said. “He understood about 75 percent of the language.”

Customers saw him studying Thai at a table there during his off hours. Alexis stopped showing up at the Buddhist center early in 2011, he said. “I didn’t think he could be this violent,” he said. “I would not have been surprised to hear he had committed suicide. But I didn’t think he could commit murder.”

Relatives contacted by reporters were stunned to hear that Alexis was suspected in the shootings. “I’d be shocked if it was him, but I don’t know,” said Weekes, his aunt, her voice trailing off.

Even as he worked for the defense contractor, Alexis was pursuing a bachelor’s degree in aeronautics as an online student at Embry-Riddle Aeronautical University. The university, in Daytona Beach, Fla., said he enrolled in July 2012 via the school’s Fort Worth campus. He remained a student in good standing, said Melanie Hanns, director of university communications.

“He was enrolled for this semester,” she said.

FBI Assistant Director Valerie Parlave asked the public to call 1-800-CALL-FBI with any details about Alexis.

Marjorie Censer, David A. Fahrenthold, Steve Hendrix, Jennifer Jenkins, Carol D. Leonnig, Ann E. Marimow, Annys Shin, Victoria St. Martin and Julie Tate in Washington and special correspondent Leslie Minora in Fort Worth contributed to this report.