The Second Avenue Subway is the most expensive underground train line in history — but transit officials defended the $6 billion price tag Monday, blaming it in part on New York City’s fire code.

The first phase of the line cost $2.7 billion per mile, while a forthcoming 1.5-mile extension to 125th Street is set to smash that record at $3.8 billion per mile.

The costs far outpace those in cities around the world, but agency bigwig Janno Lieber insisted that comparing New York to other cities is unfair because it is “different.”

“We have to have a longer conversation about the comparisons to other places,” Lieber, the agency’s chief development officer and capital construction president, said at a briefing on the agency’s new $51.5 billion capital plan. “There are a lot of things that make New York different.”

Lieber cited just one example as proof — the MTA’s adherence to New York City fire code. He argued the subway’s packed trains compound the costs of emergency exits.

“We comply with the fire code, which requires you to get people out — everybody who rides trains, and we have, 1,000 people plus on a train — to get them out of a station at [a] certain pace,” Lieber said.

“Other systems which run trains that have fewer people on them don’t have some of the same costs associated with vertical circulation to get people out,” he added.

In Los Angeles, officials plan to spend $1.1 billion per mile on a 2.6-mile-long subway extension, with six-car trains that can carry an average of 810 passengers.

Riders advocates said Monday they hope Lieber and his team revisit their cost calculations.

“If there are elements of the fire code that don’t make sense, then the MTA and the city of New York should rethink those things,” said Colin Wright of the Manhattan TransitCenter think tank. “There’s still time to review costs and make sure they’re in line with industry averages.”

MTA officials are counting on the federal government to fund the Second Avenue Subway, Lieber said. President Trump tweeted last month that he was “looking forward” to helping get the project finished.