Indian navy personnel after attending the decommissioning ceremony of India's first indigenously designed and built warship, the INS Godavari, at a naval base in Mumbai in December. (Danish Siddiqui/Reuters)

In a recent speech in New Delhi, the outspoken commander of the U.S. Pacific Command, Adm. Harry B. Harris Jr., was nearly poetic when he discussed the growing relationship between India and the United States, saying he was a “bit moonstruck” about the possibilities.

“In the not too distant future, American and Indian Navy vessels steaming together will become a common and welcome sight throughout Indo-Asia-Pacific waters,” he said, “as we work together to maintain freedom of the seas for all nations.”

The comments struck a chord — though, perhaps, not the note Harris wanted. Just a few days later, India’s defense minister, Manohar Parrikar, publicly rebuked him, saying India does not participate in joint patrols.

Growing concern over China and its naval activity in India’s back yard — the vast Indian Ocean — have brought the two once-distant militaries closer than ever before.

India participates in more military exercises with the United States than with any other country, and the two are close to signing an agreement that would allow refueling and repair of vehicles at each other’s bases — a controversial proposal that has been under discussion for more than a decade.

Yet Harris’s misfire shows that overcoming years of mistrust — during the Cold War and over U.S. support of Pakistan — will take time.

The United States is looking to shore up its reach in the region with freedom-of-navigation patrols to counter Chinese territorial encroachment in the South China Sea. India has been critical of some Chinese actions and deployed four warships to the area for exercises last month but has generally moved with caution to avoid antagonizing its mighty neighbor and key economic partner.

“Where the South China Sea is concerned, the Indian government understands the risk very clearly of getting needlessly tangled there,” Manoj Joshi, a distinguished fellow at the Observer Research Foundation, a New Delhi-based think tank, said in an interview. In a recent opinion piece, Joshi described the U.S. approach to India as an “almost brash Pentagon wooing,” coupled with “more sophisticated approach” by the State Department.

Indian Prime Minister Narendra Modi arrives Monday for a short visit to the United States, to meet President Obama and address Congress — a historic moment for a leader who was once banned from entering the United States.

In 2005, the United States government denied Modi a visa on religious-freedom grounds, after charges that he had not acted to stop Hindu-Muslim rioting in Gujarat, the state where he was chief minister in 2002, that left more than 1,000 dead.

The visit will mark the seventh time Modi and President Obama have met since the prime minister came to power in May 2014, a measure of both India’s strategic importance to the United States and what aides say is a genuine rapport between the two men. They will discuss climate change, a clean-energy partnership, and security and defense cooperation.

After India performed a series of nuclear tests in 1998, a near-blackout of military cooperation followed. Relations improved after President Bill Clinton visited in 2000, and, in 2008, the countries ratified a landmark agreement on civil nuclear cooperation. The agreement has yet to bear fruit, but Westinghouse Electric may announce a plan to build six reactors in the Indian state of Andhra Pradesh in the coming weeks.

“India is really a legacy issue for Obama,” said C. Uday Bhaskar, director of the Society for Policy Studies in New Delhi. After the nuclear-cooperation issue was settled in 2008, past estrangement moved to tentative partnership, he said.

Now, a new phase. The Modi government seems more interested in cooperating than previous governments, analysts say, and U.S. Defense Secretary Ashton B. Carter has made India a top priority, with an expansion of defense technology and trade and collaboration on aircraft-carrier design.

The United States is one of India’s top defense suppliers, resulting in $14 billion in defense contracts since 2007.

India is also seeking U.S. support as it attempts to overcome China’s opposition to its entry into the Nuclear Suppliers Group, an organization of 48 countries that aims to limit nuclear proliferation through export controls.

Yet India hedged its bets for years on the key logistics agreement that would enable the United States to refuel and repair vehicles at Indian ports and bases.

The two countries have agreed “in principle” to the deal, but the final draft has not been signed. Two other agreements — one that would provide access for India to advanced radio and satellite communications systems from the United States, another that would provide exchange of geospatial data for military and civilian use — are also pending.

The Indians had long been reluctant to sign the logistics agreement because of fears it would obligate India to support a U.S. role in future military conflicts, experts say, a fear the United States thinks is unfounded.

“There are certain apprehensions in our minds because of past experience,” said Alok Bansal, a former naval officer who is now the director of the Center for Security and Strategy at the India Foundation in Delhi. “Most people in India think that U.S. linkages come with strings attached.

“But,” he added, “it’s changing. As a new generation comes, the historical baggage gives way.”