Facebook Inc., which became the world’s biggest social network by encouraging people to share photos and messages publicly, said it is now betting on the opposite: that the future of social media lies in private messaging and small-group chats.

In a major shift in strategy, Facebook plans to offer encrypted messaging across all of its major products and allow people to make private conversations ephemeral, Chief Executive Mark Zuckerberg wrote in a blog post. It also will develop products within those messaging services—such...