He wanted to be “America’s mayor” a whole lot longer.

Rudy Giuliani secretly asked then-New York Gov. George Pataki to cancel New York City’s 2001 mayoral election so he could remain in office following the Sept. 11 terror attacks, a new book reveals.

The bombshell disclosure is contained in Pataki’s upcoming memoir of 9/11, “Beyond the Great Divide: How A Nation Became A Neighborhood.”

In an excerpt obtained by The Post, Pataki recalls how he attended a press conference with Giuliani and then-Japanese Prime Minister Junichiro Koizumi at Manhattan’s Pier 92 on Sept. 24, 2001.

As they began leaving, Giuliani — who a day before had been hailed as “America’s mayor” by Oprah Winfrey during a Yankee Stadium prayer service — asked Pataki for a “private meeting” and they walked into a small room to talk.

Following an exchange of the “usual formalities,” Giuliani “dropped a bomb,” Pataki writes.

“Governor, you have extraordinary powers to extend my term in office,” Giuliani said.

Pataki’s “heart sank,” he writes, noting that he initially backed the idea of repealing term limits so Giuliani, a fellow Republican, could seek a third term, but quickly realized it was a “bad idea both as a matter of principle and politically.”

He also describes Giuliani’s implicit request as a desperation move following an “off-the-radar public relations campaign” in which Giuliani’s team tried, but failed, to “influence lawmakers through the media.”

Pataki writes that his “mind raced” as he told himself, “Are you really, right now, after a terror attack on our state, our city, asking me to just cancel the entire election? I am a conservative. We respect the law. For God’s sake, you’re a prosecutor! You know the law.”

But instead of saying anything out loud, Pataki stayed silent as Giuliani, now one of President Trump’s personal lawyers, continued talking.

“Governor, you have the power to change the city charter to allow for me, as mayor in this time of crisis, to have an extended term,” he said.

Pataki writes that he rejected the suggestion, saying, “I don’t think I can do that, Rudy. It’s not a good idea for you or the city, and I think it’s beyond even my emergency legal authority to do this.”

But Giuliani “excitedly fired back,” saying that his counsel, Denny Young, who was present, “thinks you do have the ability,” Pataki writes.

Pataki says he agreed to have his counsel, Jim McGuire, who was also present, discuss the matter with Young, after which Giuliani’s team “pushed the issue with my staff” for several weeks.

When it became clear that Giuliani wouldn’t get his wish, Pataki writes, he arranged a brief meeting at which he admitted, “George, you are right. I don’t think you should cancel the election.”

Pataki writes that while he was “disappointed” by Giuliani’s request, “maybe I shouldn’t have been so emotional about it.”

“While some may look at Rudy Giuliani as a power-hungry politician, the reality is that he wanted to keep leading and helping with the recovery efforts. He believed staying in office was best for the city. I was sure it wasn’t,” he writes.

But Pataki adds: “Regardless of Rudy’s motivation, regardless of his raw emotions in the situation, he abandoned some of the most basic conservative principles — follow the law and relinquish power when your term is over, even in times of crisis.”

“Beyond the Great Divide,” which is being published by Post Hill Press, goes on sale April 14.