The UK’s decision to vote for a Brexit has seriously spooked stock markets, which were expecting a vote for Remain.

Watching the London market open this morning was pretty scary. The temptation to sell to prevent further losses is strong. But dumping shares in a panic sale is probably the worst decision you could make.

When faced with major surprises, stock markets are notorious for shooting first and asking questions later. It’s worth comparing the situation today to the financial crisis. Back then, there was a real risk that the global banking system could collapse.

No one is suggesting that will happen today. The UK and EU have at least two years to negotiate an exit agreement. Probably longer. Regulatory changes may be a pain in the neck, but they won’t be terminal.

A buying opportunity?

In March 2009, the FTSE 100 (INDEXFTSE: UKX) bottomed out at 3,530. Over the following six months, it rose by almost 50%. Over the following two years, it rose by almost 70%. Buying in the wake of the crash was a very profitable strategy.

The same may be true today, although it’s probably worth waiting until the dust has settled before starting to buy.

In my opinion, the reality is that most businesses will carry on operating as usual in the wake of the UK’s decision to leave the EU. Good quality companies will probably continue to do well.

Which stocks should you buy?

Shares of classic defensive stocks such as British American Tobacco, Diageo and Unilever haven’t really moved today. These businesses have traded through world wars, revolutions and the formation of the EU. Yesterday’s vote won’t derail these firms’ steady progress, but of course they aren’t cheap. Big gains are unlikely.

There may be better opportunities among banks and insurers. Shares in most of these businesses are down by between 10% and 20% today, thanks to fears that the potential loss of EU ‘passporting’ will force them to move some business into Europe.

That may be true — but in most cases these firms already have regulated operations in EU countries. Shifting some operations from London to Paris or Frankfurt probably isn’t something shareholders need to worry about. Aviva has already said that leaving the EU is expected to have “no significant operational impact”.

I believe the biggest risks and opportunities may be in the housing sector. Housing stocks have fallen by 20% or more this morning. Investors are concerned that the exit vote might trigger a UK recession and a housing market slump.

It’s hard to know how serious this risk is. So far this year, almost all housebuilders have reported record order books and strong cash generation. If the housing market remains stable, then today’s falls could be a great buying opportunity. On the other hand, housebuilders don’t look especially cheap relative to historic earnings.

What to do next?

For investors with some spare cash, now could be a good time to top up long-term holdings. If you’re fully invested already, then I’d suggest the best plan is to simply log-off and do something else!

Short-term stock market moves are generally driven by sentiment, but long-term moves are driven by value. Selling cheap because the market is scared could be a costly mistake.

How to profit from tough markets

If you're still concerned about the damage our Brexit vote might do to your portfolio, I urge you to consider the companies featured in this exclusive new report.

The Motley Fool's top experts believe these handpicked stocks should continue to do well in almost any economic climate.

The UK's decision to leave the EU is unlikely to affect the profits of these companies, thanks to their strong defensive moats.

To receive full details of these five stocks immediately, download this FREE, no-obligation report today. Just click here now.

Roland Head owns shares of Diageo, Unilever and Aviva. The Motley Fool UK owns shares of and has recommended Unilever. The Motley Fool UK has recommended Diageo. We Fools don't all hold the same opinions, but we all believe that considering a diverse range of insights makes us better investors.