Just when the improving situation in Iraq was changing President Bush’s legacy for the better, the potential meltdown of the economy is putting it back in doubt.

If Treasury Secretary Henry Paulson’s huge financial rescue package — or some modified version of it — saves the economy, Bush should share the credit.

If it fails, Bush could go down as Herbert Hoover II and Democrats, along with liberal historians, will revive the charge he’s “the worst president in American history.” And, it might stick.

Prior to the financial crisis, Bush and his backers were building a case he deserves to be listed with Harry S. Truman — an unpopular president vindicated by history. That is based largely on the fact Bush has kept the nation safe from terrorist attack and had the courage not to give up in Iraq during the war’s darkest hours and now has a chance to achieve victory.

Whatever history ultimately says about the whole Bush presidency, I think this much is certain: The second term has been a lot better than the first — and much of the credit goes to White House Chief of Staff Josh Bolten.

It was Bolten who recruited Paulson, the former Goldman Sachs chief executive officer who may or may not be the savior of the U.S. economy. For certain, he’s bold, tireless, knowledgeable and respected.

Bush deserves the credit for overruling his generals and deciding on the surge that saved Iraq from disaster, but Bolten — along with National Security Adviser Stephen Hadley — began the process of convincing Bush in early 2006 the war was going badly.

Bolten had a hand in the departure of Donald Rumsfeld as secretary of Defense and his replacement by Texas A&M President Robert Gates, who has won high marks for cool-headedness, drive and good judgment.

Under Gates, Hadley and Secretary of State Condoleezza Rice, the tenor of Bush foreign policy has changed in the second term because, one former White House aide told me, “Bush has matured. Arrogance was his fatal flaw in the first term. He’s dealt differently with the world in the second.”

Besides putting more emphasis on negotiation and multilateralism, Bush has doubled U.S. humanitarian activities, especially in Africa.

Bolten, who has been with Bush since the 2000 campaign, took over as chief of staff from the well-liked — but hands-off — Andrew Card in April 2006. Previously deputy chief of staff for policy and director of the Office of Management and Budget, Bolten told aides he wanted to “bring some mojo back” to the administration.

He gave top staffers “Bush Countdown” clocks — invented for Bush-haters to mark the days until Jan. 20, 2009 — as a reminder of how little time remained to get anything done. “Josh is a taskmaster, a perfectionist,” one former top aide says. “He’s mild-mannered, but demanding, a velvet hammer.”

His first move was to fire the White House’s disastrous — and, ultimately, traitorous — press secretary, Scott McClellan and replace him with the late Tony Snow, who’s been succeeded by Dana Perino, also a feisty and clued-in spokesperson.

Bolten not only recast the White House staff — painfully persuading his friend, Karl Rove, to give up policy and concentrate on politics — but also the Bush Cabinet, bringing in ex-Judge Michael Mukasey to replace the inept Alberto Gonzales as attorney general, respected former Idaho Sen. (and Gov.) Dirk Kempthorne at Interior and former Arizona highway commissioner Mary Peters at the Department of Transportation.

Bolten and Bush’s personnel and policy redos won’t erase a legacy of polarized politics, surging national debt and the current financial crisis. But it’s worth noting Bush did try to deal with the biggest long-term threat to the economy, unsustainable Social Security, Medicare and Medicaid costs.

His Social Security proposal was rejected by congressional Democrats, who refused to even negotiate on the subject, and the proposal to establish a bipartisan entitlement commission found no takers.

And, few Democrats besides former Securities and Exchange Commissioner Arthur Leavitt took seriously Wall Street’s penchant for inventing ever-more-arcane financial instruments. It was Fed Chairman Alan Greenspan who kept interest rates too low for too long, encouraging the housing bubble.

As Bush’s eight years run out, there will be endless thumbsucking about his legacy, with the conclusion only history will decide whether “the Bush doctrine” in all its meanings was a good thing or a bad thing.

But it’s a good question: Would Bush have done better if the people running his government in the second term had run it in the first?

I think so.

Morton Kondracke is executive editor of Roll Call, the newspaper of Capitol Hill.