America has many moments where it’s existence hung in the balance. The war of 1812 was one of those times. James Madison, in spite of populist pressure, held the course and enforced the Constitution (which, of course, he authored). IMHO he was our greatest President, followed closely by Washington.
I believe Madison is the most underrated, and perhaps the greatest considering what he did while in office and prior to being elected.