City commuters were stuck underground for more than three hours Tuesday morning when two Long Island Rail Road trains stalled inside an East River tunnel.

The trains stalled because of an Amtrak third-rail power outage, stranding about 2,000 passengers, who received emergency water, officials said.

One train — the 6:13 a.m. from Massapequa Park due into Penn at 7:08 a.m. — remained stuck until a relief engine got the train in 75 minutes late, the MTA said.

The second train — the 6:12 from Babylon that was due into Penn at 7:14 — were stuck underground for more than three hours, they said.

“It was torture,” said Michael Vitelli, who got on the 6:28 a.m. train at Merrick. “I can’t sit still, I get antsy and start having panic attacks. The window started to get foggy from people’s breath. It was getting musty and gross.Some people on the train just started yelling, ‘class-action lawsuits!’ ”

MTA officials blamed the problem on Amtrak, saying that the power went out to the third rail in the tunnel.

The power trouble comes a week after Gov. Andrew Cuomo said the state should take control of Penn Station and the rails around the transit hub because Amtrak can’t handle the job anymore.

The third-rail glitch caused delays in westbound service into Penn Station, as well as cancellations at Jamaica and diversions to Hunterspoint Avenue or Atlantic Terminal.

A woman aboard a stalled train told WNBC that the lights went out at one point. She said a conductor distributing water told passengers that the train ahead had hit the third rail.

No injuries were reported among the passengers, who reported getting emergency water but little information during the ordeal.

Many were eager to share their tales of woe.

Tara Bonet-Black 43, an editorial assistant from Belmore who works in Midtown, said she got on her Babylon line train at 8:13 — but only arrived at Penn Station at 10:50.

“I fell asleep and when I opened my eyes, the conductor said we were just waiting for a tunnel. I thought we were at Penn Station waiting for a tunnel and then I realized we were stopped at Woodside,” she told The Post.

“They barely made an announcement and the conductors barely came around. It’s awful. My monthly ticket is almost $300,” she said. “It makes me sick. I have two small kids and I’m always running around like crazy.

“For that much money, I should not have to deal with all of this,” she added. “The whole situation makes me want to cry — I could have flown to Florida in three hours.”

Helen Cho, 27, a legal assistant from Oyster Bay, said her train was delayed by an hour.

“We were stopped right before the tunnel. There were many other trains before us and they were letting us in one by one,” Cho told The Post. “It happens way too often. I have gotten used to it. Today is extreme but there are delays and problems about once a week.”

Paul Gajer, 63, an attorney who works in Midtown and lives in Manhasset, complained about the lack of information being provided on the Port Washington line.

“They said they were having signal problems and there was a train stuck in one of the tunnels,” he said. “It was frustrating because the information was very limited and they didn’t explain what was going on or how long you would be there. I had a seat but a lot of people were standing.”

Alyssa Greaney, 19, of Sea Cliff in Nassau County, said she was stuck for two hours on the first day of a new job.

“They said the power went out. We were stuck behind some trains,” she said. “It’s so annoying to sit on the train for two hours.”

Jean Wolschlager, an accountant from Huntington, said she was on the Port Jefferson line when she received text alerts about the third rail malfunction.

“All of a sudden we stopped at Woodside and stopped moving,” Wolschlager said. “It’s a pain in the neck. I think they don’t know how to run the train.”

She said her boss was understanding.

“What can I do, get out there and push the train?” she said.

Frustrated passengers took to social media to air their complaints.

“Welcome back from your Memorial Day weekend. To start the week off right the #LIRR is screwing you over with major delays #wedeservebetter,” @Keith_A_20 tweeted.

“@lirr should I formally change my address? Because I think I live on this Babylon line train now. #lirr #TerribleService,” @underyour_radar posted.

“I honestly think there is going to be a riot on my train…already an hour late & still at Woodside, and tempers are starting to flare #LIRR,” wrote @schurrthangg.

And @beachinangelina said she ran out of songs to keep herself entertained.

“I’ve been stuck on this train for so long I ran through my Spotify playlist 3 times #LIRR,” she fumed.

Meanwhile, MTA service also was disrupted Tuesday morning.

The M trains were delayed because of a broken rail and E and F trains were delayed because of a stalled train in Queens.

NYC Transit is cross-honoring LIRR tickets as follows:

1, 2, 3, A, C and E trains at 34 St-Penn Station

7 trains at Hunterspoint Ave, Woodside 61st St and Mets-Willets Point

E, J and Z trains at Jamaica Sutphin Blvd-Archer Avenue

E, F, M and R trains at Forest Hills 71st Avenue

E and F trains at Kew Gardens Union Turnpike

Amtrak — which owns Penn Station and leases the tracks to the MTA and NJ Transit — has said it plans to close several tracks for up to two months during the summer for infrastructure improvements.

The power trouble comes a week after Gov. Andrew Cuomo said the state should take control of Penn Station because Amtrak can’t handle the job anymore.

Additional reporting by Lorena Mongelli