The ambulances and police cars came to a screeching halt outside the Gowanus Inn and Yard, a hip, ultramodern hotel that had recently opened on an edgy strip of Union Street in Brooklyn.

But the first responders were 48 hours late. James Dolan, a 36-year-old former Marine and computer security expert, had hanged himself in his room two days before, on Dec. 26, according to the NYPD.

Curious crowds gathered on Dec. 28 outside Dinosaur BBQ and an auto mechanic’s shop across the street from the new hotel whose boxy, gray industrial facade gives it an institutional air, like a hospital or a prison.

“They just opened that place, and someone goes there to die,” said a worker at Tomato N’Basil pizzeria around the corner, on Fourth Avenue. He had been among the crowds when they wheeled Dolan’s body out the door in a bag.

“What could have been so bad for him to do that?” he asked.

The answer may never be known. What is known is Dolan was the second member of a small team of brilliant Internet activists who developed SecureDrop — a whistle-blower submission system — to commit suicide by hanging in Brooklyn.

The first was Aaron Swartz, the wunderkind computer programmer, entrepreneur and activist who co-founded the social news site Reddit when he was still in his teens. According to the NYPD, Swartz, 26, hanged himself with a belt in the Crown Heights apartment he shared with his girlfriend in January 2013. His death came a month before he was scheduled to go on trial in federal court on wire-fraud and hacking charges. Swartz faced 35 years in jail and more than $1 million in fines for allegedly downloading millions of files in 2011 from the online academic archive JSTOR at MIT. Prosecutors said Swartz intended to distribute the articles for free online.

Swartz’s death was greeted with widespread outrage across the cyber universe where he was known as an outspoken activist hero, advocating for the protection of the First Amendment and successfully leading the charge in 2011 against the Stop Online Piracy Act, a federal bill that he felt would severely curb freedom of speech on the Internet.

A month after his death, activists associated with the militant group Anonymous hacked the State Department’s site, publishing the personal data — addresses, phone numbers, and personal e-mails — of consular officials and staff around the world on a site called ZeroBin.

“Our reasons for this attack are very simple,” Anonymous said in a statement after the attack. “You’ve imprisoned or either censored our people. We will not tolerate things as such . . . When the lions roar you will hear them. And when it’s feeding time you’ll be our dinner. Aaron Swartz this is for you.”

And at his funeral in his hometown of Highland Park, Ill., Swartz’s grief-stricken father pointed a finger at the federal government for what he described as an overzealous pursuit of his son.

“Aaron did not commit suicide,” said Robert Swartz. “He was killed by the government. Someone who made the world a better place was pushed to his death by the government.”

There were no such blunt pronouncements at James Dolan’s New York funeral earlier this month — even if his closest friends and family might have felt the same way. Like Swartz, Dolan was a digital activist, working to help non-profits and reporters expose government corruption without putting their lives at risk. But unlike Swartz, Dolan did everything to make himself invisible. In an age dominated by social media, the computer security expert and Iraq war veteran had virtually no online presence.

Yet, shortly after his death was announced in a blog post earlier this month, the Internet lit up with questions, hinting at conspiracies. WikiLeaks noted in a tweet: “Second developer of WikiLeaks inspired submission system ‘SecureDrop’ security expert James Dolan, aged 36, has tragically died. He is said to have committed suicide. The first, Aaron Swartz, is said to have taken his own life at age 26, after being persecuted by US prosecutors.”

On Jan. 14, days after Dolan’s suicide was announced publicly, one Twitter user mused, “Both James Dolan and Aaron Swartz who were working on the whistle-blowing tool committed suicide . . . we’re supposed to believe that . . . I don’t freakin’ think so!!!!”

One of Dolan’s associates dismissed the online chatter as “totally unfounded and false conspiracies,” adding that Dolan never had anything to do with WikiLeaks. Other sources told The Post that Dolan suffered from depression linked to post-traumatic stress disorder, which set in after he returned from his second tour of duty in Iraq in March 2005.

“He was very humble and very private,” said a close associate who did not want to be identified. “He wouldn’t have wanted anyone to talk about him, so we are respecting that now.”

Secrecy had been part of Dolan’s life, at least since his first deployment to Iraq in 2003. Little is known about him, other than that he grew up in Hicksville, LI, and at 21, he was already a talented and highly trained cyber expert with a top-secret security clearance. A month before President George W. Bush launched Operation Iraqi Freedom — the US invasion of Iraq in March 2003 — Dolan was already on the ground in the country as “a data network specialist,” according to a spokeswoman for the US Marine Corps’ Office of Manpower and Reserve Affairs.

Cyber specialists employed by the Marines install and maintain highly sensitive computer networks. The spokeswoman for the Marines would not elaborate on Dolan’s exact duties in Iraq, noting that there were pages missing from his report.

But during Dolan’s second deployment to Iraq, from September 2004 through March 2005, the war had entered its bloodiest phase. On Nov. 7, US Marines led Iraqi and British troops in Operation Phantom Fury in Fallujah, the second attack on the city long considered a stronghold of support for Iraqi leader Saddam Hussein, 25 miles outside Baghdad. The US military said the battle had involved the worst urban combat since Vietnam, and deaths included 95 American troops and 1,350 insurgent fighters.

But the Second Battle of Fallujah, as it was known, was controversial for another reason: The US military’s use of white phosphorous, which is considered a banned chemical weapon under the Geneva Convention when used against civilians, causing horrific burns. The Pentagon said it used the substance legally as a device to create smokescreens and mark targets, not against individuals.

It’s not clear what Dolan, a sergeant, witnessed in Fallujah because, as the close associate told The Post, “he never talked about Iraq” even though he emerged from the war with a chestful of commendations.

His combined 11 months of service in the country as part of the US’s most elite fighting force haunted him, and would come to define James Dolan when he re-entered civilian life, his friends told The Post.

“He often cited the Iraq War as his inspiration for wanting to help journalists and whistle-blowers,” wrote Trevor Timm, executive director of the San Francisco-based Freedom of the Press Foundation in an online tribute earlier this month accompanied by a photo of Dolan. “It made him realize government needed to be much more transparent and accountable.”

Back home, Dolan worked as a cyber security expert for various firms, but he also donated his time to develop systems that would allow non-profits and human-rights groups to root out high-level corruption without compromising their own security.

In 2012, he joined Swartz and journalist Kevin Poulsen to develop SecureDrop, an “open-source whistle-blower submission system that media organizations can use to securely accept documents from and communicate with anonymous sources,” according to the Freedom of the Press Foundation. The non-profit, whose mission is to protect “adversarial journalism” around the world, now manages the program, which it inherited after Swartz’s death in 2013.

According to Timm, Poulsen donated SecureDrop to the foundation “in the hopes that we could revive it and get it in a place where more news organizations could use it,” he said.

In order to help news organizations across the country install SecureDrop, Dolan, who was single, quit his “high-paying security job at a large company” and joined the journalism foundation. According to Timm, Dolan happily took an 80 percent pay cut in order to finesse SecureDrop.

“He poured his heart and soul into the work, traveling to newsrooms around North America to teach IT staffs and journalists in person,” wrote Timm on a Jan. 9 blog post.

The system uses multiple levels of encryption in order to protect the identity of whistle-blowers who want to send information securely. SecureDrop is now used by both media companies and human-rights organizations around the world.

“We would not be able to do our work without SecureDrop,” said John Tye, the founder and executive director of Whistle-blower Aid, a Washington-based non-profit group of lawyers who defend whistle-blowers in court. “We’re a scrappy startup and we want to be able to take cases all over the world. There are multiple levels of encryption that allow sources to report government lawbreaking without breaking the law.”

When his work was finished with the press foundation, Dolan moved to San Diego to work as head of Internet security for Classy, a crowd-funding site for charities.

“James was brilliant, unique and kindhearted,” said Scot Chisholm, Classy’s CEO and co-founder. “He was always deeply committed to his role and to our clients’ information safety. The work he did before coming to Classy was incredibly honorable.”

Dolan was still working for Classy at the time of his death, and was in New York City for the holidays, according to the associate.

War hero and Internet activist — it’s the dichotomy that made up the complicated life of James Dolan.

As his former colleague Swartz noted before he died, “Everyone made themselves the hero of their own story. Everyone took it as their job to save this crucial freedom.”

Those closest to Dolan would agree that he lived — and died — by that philosophy.