Yes, in certain circumstances, a shape can be registered as a trademark if it is distinctive and does not merely describe the goods or serve a functional purpose.
Shapes that are dictated by the nature of the product itself or that are necessary to achieve a technical result cannot be registered as trademarks; those restrictions exist to prevent one company from monopolizing functional design elements. What can be registered is a shape that has acquired distinctiveness through use and that consumers recognize as identifying a specific commercial source. The Coca-Cola bottle and the Toblerone chocolate bar shape are well-known examples.
Shape marks are typically the hardest type of trademark to register, precisely because the bar for distinctiveness is high and functional shapes are excluded.