In an extraordinary 4½-hour interview from behind bars, convicted Ponzi schemer Bernie Madoff told a San Francisco trial lawyer yesterday that he got away with his $65 billion scam because regulators weren’t paying attention.

There were times “that he [Madoff] visited with the SEC. . .when he thought, ‘They got me,’ ” the attorney, Joseph Cotchett, told a group of reporters camped outside a federal prison in Butner, NC, where Madoff is serving a 150-year sentence.

Cotchett, who represented former CIA agent Valerie Plame against the Bush administration, landed the interview after threatening to sue members of Madoff’s family, including his wife, two sons and brother.

Armed with two packs of quarters so that Madoff could get food from the prison vending machines, Cotchett and his partner Nancy Fineman grilled Madoff and his attorney about who knew what and when.

In order to take the heat off certain members of his family, Madoff “spelled out how the fraud was committed” during the face-to-face session.

“He gave us a lot of information that we believe will help us aid the victims tremendously,” Cotchett said. “He was very direct and didn’t hold back anything.”

“The detail was extraordinary. I was very surprised at how candid and open he was.”

Cotchett said that Madoff told him that “it all started in the mid-’90s,” and that the disgraced financier provided “the details of how it all started.”

But, Madoff was “very remorseful.”

Cotchett said Madoff repeatedly apologized for the harm he caused victims, about a dozen of whom are represented by Cotchett.

Cotchett declined to elaborate on specifics disclosed by Madoff yesterday, saying, “The details of how it all went down are going to be more clearly laid out in the next complaint,” which he said should be filed in the next few weeks.

Cotchett said it’s safe to assume Madoff’s brother, Peter, who served as his firm’s chief compliance officer, will remain a target of the complaint.

Cotchett has yet to decide whether to target Madoff’s wife Ruth or their sons Andrew and Mark.

The lawyer said he was Madoff’s first visitor, adding that “his wife has not been here, his son has not been here, no one’s been here.”

Cotchett said Madoff is estranged from his sons.

“The sons have not spoken with their father or mother since Madoff’s arrest on Dec. 11.”

“We’re the first people to meet with Bernie since he’s been here,” said Cotchett, who described him as healthy looking.

“He seems to be working out,” said Cotchett, adding that Madoff was looking “a lot better” than he’s looked in pictures of late.