Islamic scholars and financial experts agree that if certain conditions are met, it is lawful to invest in the stock market. Any earnings that result from such investments will be halal. The logic behind this argument is that when one purchases shares in a company he actually becomes a shareholder and thus becomes a partner in the business. Thus, this arrangement is akin to the Islamic concept of Musharakah. However, there are a some conditions that must be satisfied before one is allowed to invest in stocks.
Allah knows best...