What's the smartest thing to do with $5,000? At the top of the list for most people will be building an emergency nest egg and paying down debt. But if you've already checked off those boxes, consider buying the stocks of exceptional companies that are poised to deliver solid long-term gains.

Different investors will have different opinions about which are the best stocks to invest $5,000 in right now. Here's why I think that Alphabet (GOOG -0.86%) (GOOGL -0.83%), MercadoLibre (MELI -1.99%), and Vertex Pharmaceuticals (VRTX 1.25%) are the top picks.

1. Alphabet -- an inexpensive tech juggernaut

Thanks to its 20-for-1 stock split conducted in July, you can buy a lot more shares of Alphabet with less money than you could've in the past. And now is a great time to buy this tech stock.

For one thing, Alphabet's share price has fallen more than 30% year to date. This decline has given the company its lowest price-to-earnings multiple in nearly a decade.

Alphabet also reported nearly $125 billion in cash, cash equivalents, and marketable securities as of June 30. The company bought back close to $28.5 billion of its shares in the first half of this year. More stock buybacks are almost certainly on the way. Alphabet's management wouldn't place such big bets on the company if they weren't convinced that its future remained bright.

There are plenty of reasons for investors to be confident about Alphabet's future as well. The company's moat for Google Search is as strong as ever. Alphabet has multiple drivers of other growth, including Google Cloud, YouTube Shorts, and its famous "other bets." I predict that this stock won't remain so attractively valued for too much longer.

2. MercadoLibre -- dominating in Latin America

You won't be able to buy many shares of MercadoLibre with $5,000 and still have money to invest in the other two stocks on this list; shares of the Latin American company currently trade at close to $875 even after sinking more than 30% this year. But this stock is worth the price, in my view.

MercadoLibre's business is humming along despite some economic headwinds in Latin America. In the second quarter, net revenue skyrocketed 56.5% year over year on a constant-currency basis. Total e-commerce gross merchandise volume hit an all-time high. The company's fintech business also continued to grow robustly.

There's a lot more room for MercadoLibre to grow. The e-commerce penetration rate in Latin America remains relatively low compared to the U.S., but is projected to expand by close to 45% over the next three years. Latin America ranks as one of the hottest fintech markets in the world.

While MercadoLibre has competition in the region, it's clearly the leader, and I think it will stay at the top for years to come. Without question it's a top growth stock to buy right now.

3. Vertex Pharmaceuticals -- momentum and more

If you're looking for a stock to buy that's already a winner in a down market, I highly recommend Vertex Pharmaceuticals. Shares of the biotech have soared more than 35% so far this year. I expect that Vertex will rise even more in 2023 and beyond.

Vertex remains highly profitable with strong revenue growth thanks to its cystic fibrosis (CF) therapies. The drugmaker has the market to itself: Its closest rivals are years away from even having a chance to win regulatory approvals for their CF pipeline candidates. Vertex believes it can continue capturing market share by securing reimbursement deals and additional approvals for younger ages for its current CF therapies.

But the company has its sights on more than CF. Vertex and CRISPR Therapeutics plan to file soon for regulatory approvals of exa-cel in treating (actually, curing) sickle cell disease and transfusion-dependent beta-thalassemia. The company's pipeline also includes two other programs that have blockbuster potential -- one that targets APOL1-mediated kidney disease, and a non-opioid drug for acute pain.

On top of all of this, Vertex thinks that it's on the right path to developing a cure for type 1 diabetes. The company has a cash stockpile of $9.3 billion to bolster its pipeline. And the stock appears to be cheap, with a price-to-earnings-to-growth (PEG) ratio of only 0.4.

High inflation, rising interest rates, and fears of a recession shouldn't slow Vertex down at all. I believe that in the midst of so much uncertainty, it may be the best stock to buy right now.