MENLO PARK, Calif. — Narendra Modi and Mark Zuckerberg have much in common.
Mr. Modi, the prime minister of India, oversees a nation of 1.25 billion people. Mr. Zuckerberg, the chief executive of Facebook, runs a social network with 1.5 billion active users. Both see themselves as global leaders pushing for broad social change, and both routinely use social media to communicate with their many millions of fans.
On Sunday, the two men engaged in a mutual admiration session at Facebook’s Silicon Valley headquarters, with Mr. Modi fielding preselected questions from a crowd of Facebook employees and guests invited by the Indian Embassy.
Mr. Modi praised social networks like Facebook, Twitter and even China’s Weibo as useful tools for governing and diplomacy.
“The strength of social media is it can tell government where they are going wrong,” Mr. Modi said. “We used to have elections every five years. Now we have them every five minutes.”
Mr. Modi’s visit to Facebook came halfway through his weekend tour of Silicon Valley, where he has been meeting with technology executives and seeking their ideas and assistance in bringing India fully into the digital world.
Silicon Valley has been eager to assist. India is the world’s fastest-growing major economy, and use of the Internet and smartphones is growing rapidly, providing new markets for American companies.
In addition, tens of thousands of Silicon Valley technology workers are of Indian descent and eager to give something back to their country of origin.
The prime minister, an avid user of Twitter and Facebook, sees technology as a way to lift India out of poverty.
“In this digital age, we have an opportunity to transform the lives of people in ways that were hard to imagine just a couple of decades ago,” Mr. Modi said in San Jose on Saturday in a dinnertime speech to about 500 technology leaders, including the chief executives of Microsoft, Google, Adobe and Uber.
Naren Gupta, a founder of the Silicon Valley investment firm Nexus Venture Partners, who helped organize Mr. Modi’s visit, said the prime minister wants tech companies to help him bring about that transformation.
“Innovation is a state of mind, and he is saying, help him bring that state of mind to India,” Mr. Gupta said. “Big changes are pretty much impossible to make. What you need to do in a democracy is take a thousand little steps.”
Mr. Modi’s message of partnership with American technology companies has been carefully choreographed to appeal to his constituents back in India, a country that is rapidly discovering the Internet and the start-up culture. The prime minister’s Bharatiya Janata Party has encountered setbacks in its legislative agenda and will soon face state elections.
A group of academics raised concerns about the free speech and privacy policies of Mr. Modi’s government in an open letter before his visit. Outside Facebook headquarters, Sikh separatists also protested his visit.
On Saturday, Mr. Modi stopped by Tesla Motors, the electric-car maker, and held private meetings with three of the technology world’s most powerful executives: Timothy D. Cook of Apple, Sundar Pichai of Google and Satya Nadella of Microsoft.
At the subsequent dinner, the tight connections between American companies and the Indian government were apparent.
Mr. Modi announced that Google had agreed to provide free public Wi-Fi in hundreds of Indian railroad stations, which are major transit and social hubs for their communities.
Recalling his childhood in India, Mr. Nadella pledged that Microsoft would help India bring wireless Internet to its 500,000 villages, but offered no details. “What opportunities can we unlock, what changes can we spark?” he said.
Qualcomm, a chip maker with thousands of employees in India, promised $150 million to finance Indian start-ups.
After the Facebook visit on Sunday, Mr. Modi planned to visit Google and Stanford University, and to drop by a meeting of Indian tech entrepreneurs. In the evening, he was scheduled to address a sold-out crowd of about 18,000 people, mostly Indo-Americans, at an arena in San Jose.