The Maryland man accused of blasting his way into a newspaper office and killing five staff members with a shotgun appeared to have a longstanding grudge over a 2011 column that reported his guilty plea to criminal harassment, court records show.

"This was a targeted attack on the Capital Gazette," Deputy Anne Arundel Police Chief Bill Krampf said Thursday. "He entered the building with a shotgun, and he looked for his victims as he walked through the lower level."

Jarrod Ramos, 38, was charged Friday with five counts of first-degree murder after the Thursday afternoon shooting at the Capital Gazette newspaper in Maryland's capital of Annapolis. Ramos was not cooperating with law enforcement.

Multiple senior law enforcement officials told NBC News that Ramos had been identified through the use of facial recognition software and that authorities were executing a search warrant at his home in Laurel in neighboring Prince George's County.

Court records show that Ramos pleaded guilty in July 2011 to criminal harassment in Anne Arundel County, where the Capital Gazette is based. A 90-day jail sentence was suspended, and Ramos was placed on 18 months' supervised probation.

Five days later, the Capital Gazette published a column headlined "Jarrod wants to be your friend," profiling the woman who said she was the victim of Ramos' harassment. The article is no longer on the newspaper's website, but it was reprinted in full in the court documents.

In the column, the woman, whose name was withheld, claimed that Ramos, a former high school classmate, tracked her down on Facebook and then harshly harassed her through email for as long as two years.

The column quoted her as saying that Ramos urged her to kill herself and that the bank where she worked put her on probation because of "an email from Ramos and a follow-up phone call in which he advised them to fire her."

The column said she was laid off a few months later and "believes, but can't prove, it was because of Ramos."

In July 2012, Ramos, representing himself, sued the Capital Gazette; Eric Hartley, a former reporter who wrote the column; and Thomas Marquardt, the newspaper's publisher at the time, in Prince George's County Circuit Court alleging defamation. He filed a longer complaint in October 2012, two months after the statute of limitations for the alleged defamation had expired, adding an allegation of invasion of privacy.

Jarrod Ramos Anne Arundel County Police

The circuit judge dismissed the complaint in 2013, saying: "There is nothing in those complaints that prove that anything that was published about you is, in fact, false. It all came from a public record. It was of the result of a criminal conviction. And it cannot give rise to a defamation suit."

Ramos appealed, and in September 2015, the appeals court upheld the dismissal, writing that Ramos "never alleges that any basic fact contained in the article about his guilty plea is actually false."

"The appellant was charged with a criminal act," the court wrote. "The appellant perpetrated a criminal act. The appellant plead guilty to having perpetrated a criminal act. The appellant was punished for his criminal act. ... He does not appear to have learned his lesson."

Marquardt, the former publisher of the Capital Gazette, told the Baltimore Sun that he wasn't surprised Ramos was identified as the suspect because he began harassing the newspaper's staff shortly after the 2011 article was published.

"I was seriously concerned he would threaten us with physical violence," Marquardt said Thursday. "I even told my wife, 'We have to be concerned. This guy could really hurt us.'"

He added that he called police on Ramos in 2013 and was thinking of filing a restraining order, but decided against it.

Annapolis Police Chief Scott Baker confirmed on "Today" that police became involved with the incident five years ago, but the newspaper didn't want a formal investigation "because they were afraid it would exacerbate the situation."

"There were verbal threats toward staffers," Baker said.

John Frenaye, the founder of Eye on Annapolis, a local news site, said Ramos trolled him from 2013 to 2015, repeatedly airing his gripes against the Capital Gazette. (Eye on Annapolis and the Capital Gazette are not affiliated.)

"Any time it's that kind of troll, I just kind of ignore that," said Frenaye, who told NBC News he doesn't remember responding to Ramos or ever having written about him.

"I remember looking at it and thinking, 'Do I have to worry about it?' and thinking, 'No, his bug is with the Capital and Eric.' He had nicknames for them, too" — like "Slob" instead of Bob — Frenaye said.

"It's all sort of flooding back," Frenaye said. "I think he thought he had an audience, but I don't remember even reporting on him at all."

A few hours before the shooting Thursday, a profane tweet was posted to a Twitter account under Ramos' name, specifically calling out the author of the appeals court opinion. Scores of similar tweets target the Capital Gazette and Anne Arundel County political, legal and community leaders going back several years. An analysis by NBC News reveals that the account named the Capital Gazette in 149 of 876 tweets.

A particularly chilling tweet was posted on Aug. 26, 2015 — the same day a disgruntled employee of WDBJ-TV in Roanoke, Virginia, fatally shot and killed two reporters live on television.

The tweet featured an illustration depicting Vester Lee Flanagan II, the gunman in the Roanoke shooting, pointing his gun at a picture of Hartley, the author of the Capital Gazette column, along with a previous address for Hartley.

Krampf, the deputy police chief, said "general threats" were made toward the Capital Gazette as recently as Thursday.

"We know that there were threats sent through social media by this person," he said, adding: "This person was prepared today to come in, this person was prepared to shoot people. His intent was to cause harm."