Bush should have won this one by about 8-10 percentage points, given the state of the economy during the 2004 election. Kerry ran a very unfocused campaign, and he allowed the Bush camp to define the terms of the debate, which is always a huge mistake. It should have never been so close, and it's a testament to Bush's blunders that Kerry was even in the hunt.
Bush and Karl Rove planned the Iraq War with the expectation that the victory over there would yield him a second term. Turns out that what sustained his efforts was not the war (it was actually a net negative, considering that Abu Gharib, along with the insurgency were hurting Bush's numbers), it was the economy, which was rebounding in the face of Greenspan's deliberately low interest rate policies that was driving the real estate market and the financial sector in particular. Bush's political team wasn't really counting on the economy recovering so strongly from the 2001 recession. They were hoping that national security would carry the day, but it really didn't for them. What decided it in their favor was ultimately the economy at the time.
Bush's father always blamed his 1992 loss on Fed Chairman Alan Greenspan, whom Bush contended kept interest rates too high during that election year, thus creating only weak growth. Greenspan however reciprocated for GW Bush by lowering interest rates to recover from the 2001 recession, which was very shallow, especially in comparison to other post-war recessions.
Iraq almost cost Bush his re-election, and it ultimately became a huge burden for him during his snake bitten 2nd term, which was defined by various policy failures, plunging poll numbers, and a plummeting economy.
Perhaps if Bush had known in hindsight that his second term would have been a disaster, he would have just retired after 2004!