Good debate, one I ponder often. There is obviously no right or wrong answer.
A key point is that pre-paying your mortgage is a GUARANTEED rate of return. If you make the decision to invest in the stock market instead, then you must be compensated by an appropriate equity risk premium over and above your mortgage interest rate. The equity risk premium is usually in the neighborhood of 4-5% over short term treasuries which means that you need to expect to earn a rate of return of this amount over and above your mortgage rate. So if your mortgage rate is 4% you need to have an expected rate of return in the stock market of 8-9% in order for you to be appropriately compensated for the risk you are taking by investing in the stock market. If you itemize on your taxes you could use your expected after-tax mortgage rate for the analysis.
Here is a good piece on expected stock market returns from current levels. It's a few months old, but still applicable.
http://cornicecapital.com/AlpineAdvisor/2013/04/25/how-it-ends/BTW, Jeffrey has good insights every week, well worth a read. It's free.
From his analysis, stocks can be expected to return approx 4%/yr over the next 10 years. Now these are just models and certainly not an exact science but you need to have some sort of baseline expectation for this analysis. The model returns change constantly so if the corporate economy starts to decline or if the stock market tanks then that will change expectations going forward.
So, I would suggest that most would benefit more by pre-paying their mortgage. However, if you have proven over a lengthy period of time that you can beat 8-9%/year with your investing prowess, then by all means invest instead of pre-paying the mortgage. If this applies to you, then you should be renting (buying the house you live in is a terrible investment) and investing even more in the stock market. However, the vast majority of individuals are TERRIBLE investors. Studies have shown time and again that they underperform the market significantly, always buying at the highs and puking up their stocks at the lows. I'm sure most here are above average investors, but for the vast majority of folks they would do better paying off their mortgage.
Personally, I take the middle road by paying extra on the mortgage and investing. I'm paying enough to cut my mortgage term in half and investing the remainder. It does not have to be an all or none proposition. I can also tweak this over time. For example if the stock market drops significantly I would probably allocate more to the market.
Cheers!
Jason