MEXICO CITY — For the past seven years, Mexico and the United States have put aside their tension-filled history on security matters to forge an unparalleled alliance against Mexico’s drug cartels, one based on sharing sensitive intelligence, U.S. training and joint operational planning.But now, much of that hard-earned cooperation may be in jeopardy.The December inauguration of President Enrique Peña Nieto brought the nationalistic Institutional Revolutionary Party (PRI) back to power after 13 years, and with it a whiff of resentment over the deep U.S. involvement in Mexico’s fight against narco-traffickers.The new administration has shifted priorities away from the U.S.-backed strategy of arresting kingpins, which sparked an unprecedented level of violence among the cartels, and toward an emphasis on prevention and keeping Mexico’s streets safe and calm, Mexican authorities said.Some U.S. officials fear the coming of an unofficial truce with cartel leaders. The Mexicans see it otherwise. “The objective of fighting organized crime is not in conflict with achieving peace,” said Eduardo Medina Mora, Mexico’s ambassador to the United States.Interviews with more than four dozen current and former U.S. and Mexican diplomats, law enforcement agents, military officers and intelligence officials — most of whom agreed to speak about sensitive matters only on condition of anonymity — paint the most detailed public portrait to date of how the two countries grew so close after so many years of distance and distrust, and what is at stake should the alliance be scaled back.U.S. officials got their first inkling that the relationship might change just two weeks after Peña Nieto assumed office Dec. 1. At the U.S. ambassador’s request, the new president sent his top five security officials to an unusual meeting at the U.S. Embassy here. In a crowded conference room, the new attorney general and interior minister sat in silence, not knowing what to expect, next to the new leaders of the army, navy and Mexican intelligence agency.In front of them at the Dec. 15 meeting were representatives from the U.S. Drug Enforcement Administration (DEA), the CIA, the FBI, the Office of the Director of National Intelligence and other U.S. agencies tasked with helping Mexico destroy the drug cartels that had besieged the country for the past decade.The Mexicans remained stone-faced as they learned for the first time just how entwined the two countries had become during the battle against narco-traffickers, and how, in the process, the United States had been given near-complete entree to Mexico’s territory and the secrets of its citizens, according to several U.S. officials familiar with the meeting.The administration of former president Felipe Calderon had granted high-flying U.S. spy planes access to Mexican airspace for the purpose of gathering intelligence. Unarmed Customs and Border Protection drones had flown from bases in the United States in support of Mexican military and federal police raids against drug targets and to track movements that would establish suspects’ “patterns of life.” The United States had also provided electronic signals technology, ground sensors, voice-recognition gear, cellphone-tracking devices, data analysis tools, computer hacking kits and airborne cameras that could read license plates from three miles away.Under a classified program code-named SCENIC, the CIA was training Mexicans in how to target and vet potential assets for recruitment and how to guard against infiltration by narco-traffickers.In deference to their visitors, the U.S. briefers left out the fact that most of the 25 kingpin taken off the streets in the past five years had been removed because of U.S.-supplied information, often including the location of top cartel members in real time, according to people familiar with the meeting. The CIA and Calderon declined to comment for this article.Also unremarked upon was the mounting criticism that success against the cartels’ leadership had helped incite more violence than anyone had predicted, more than 60,000 deaths and 25,000 disappearances in the past seven years alone.Meanwhile, the drug flow into the United States continued unabated. Mexico remains the U.S. market’s largest supplier of heroin, marijuana and methamphetamine and the transshipment point for 95 percent of its cocaine.No one had come up with a quick, realistic alternative to Calderon’s novel use of the Mexican military with U.S. support. But stopping the cartel violence had become Peña Nieto’s top priority during the campaign. The U.S. administration didn’t know what that meant. Some feared a scaling back of the bilateral efforts and a willingness to trade the relentless drive against cartel leaders for calmer streets.When the Dec. 15 meeting concluded, Mexico’s new security officials remained poker-faced, “They said they were very appreciative to have received so much information,” said one U.S. official familiar with the meeting. We will be in touch, they added, and left.The roots of cooperationU.S. involvement in Mexico’s deteriorating internal security first peaked in the mid-1980s when the cocaine epidemic in the United States turned the southern neighbor into a prosperous distribution route north. In 1986, President Ronald Reagan signed a National Security Decision Directive instructing U.S. law enforcement and intelligence agencies to help defeat the growing narco-trafficking menace worldwide.Beginning in the late 1980s, a massive U.S. air, sea and land effort was shutting down many Caribbean drug routes. The traffickers were increasingly forced to move their product through the only territory left unhindered: Mexico.Mexico’s secret security ties with the United States date at least to the Cold War, when Mexico City was a hub of intrigue, the “Beirut of the Western Hemisphere,” according to intelligence history scholar Sergio Aguayo. To keep an eye on the United States, the Soviet Union and China had their largest embassies here, necessitating a large CIA presence.Back then, the Mexican intelligence service, CISEN, “was basically run by the CIA,” according to one former CISEN official. Although that has changed with time, the unusually close relationship between Mexican presidents and CIA chiefs has not. Then-CIA director David H. Petraeus attended a party at the Mexican Embassy in Washington in 2011 and visited Calderon in Mexico last year. As many of his predecessors had done, Calderon usually met with the CIA director when he came to Washington.The CIA’s importance here can be explained, in part, by the historically strained dealings between Mexico and the DEA and U.S. military. “There was a void that the CIA stepped into,” said Jeffrey S. Davidow, a former U.S. ambassador to Mexico and author of a book about the prickly relationship between the two countries.In the mid-1980s, the DEA had been virtually banished from the country because of its aggressive pursuit of a slain DEA agent’s killers. But that relationship has improved greatly in the past five years. Now, the DEA has more employees in Mexico than in any other of its 67 foreign posts.In 2000, a political earthquake in Mexico paved the way for a less suspicious era between the two neighbors. The 71-year political reign of the authoritarian and corrupt PRI ended with the election of Vicente Fox of the National Action Party as president. The Sept. 11, 2001, terrorist attacks on the United States turned the new openness into unprecedented bilateral action against terrorism.The two countries fortified the border with personnel and surveillance technology. Eventually, a protocol was worked out for Mexico to stop, detain and interrogate non-Mexicans traveling north toward the United States. Mexican authorities allow U.S. officials to remotely question third-country nationals of concern to the United States, according to Mexican and U.S. officials.Clamping down on illegal border crossings, however, had an unintended consequence: It upset agreements among the cartels over smuggling routes, sparking yet more violent competition.By the time Calderon was inaugurated in late 2006, many experts believed that Mexico was losing control of parts of the country. Even before his inauguration, Calderon pleaded with President George W. Bush to help the Mexican military quash the cartels, according to Antonio Garza, then U.S. ambassador to Mexico, who attended a meeting between the presidents.Bush agreed to help, and the Merida Initiative, a $1.9 billion aid package for military training and equipment and judicial reform, set the framework for a new level of U.S.-Mexican cooperation. In a little-noticed move, the Office of the Director of National Intelligence took a leading role in the U.S. effort to defeat the cartels, signaling the importance of intelligence in combating organized crime.By then, cartels had begun employing assassination squads, according to Guillermo Valdes, who was CISEN director at the time. CISEN discovered from a captured videotape and a special analytical group it set up that some of the cartels had hired former members of the U.S.-trained Guatemalan special forces, the Kaibiles, to create sociopathic killers who could behead a man, torture a child or immerse a captive in a vat of acid.Anxious to counterattack, the CIA proposed electronically emptying the bank accounts of drug kingpins, but was turned down by the Treasury Department and the White House, which feared unleashing chaos in the banking system.As the Mexican death toll mounted, Calderon pleaded with Bush for armed drones. He had been impressed by the results in Iraq and Afghanistan, two former U.S. officials said. The White House considered the request, but quickly rejected it. It was far too likely to result in collateral damage, they said.Violence deepened tiesBy 2009, President Obama’s first year in office, horrific scenes had become commonplace throughout Mexico: severed heads thrown onto a dance floor, a half-dozen bodies hanged from a bridge, bombs embedded in cadavers. Ciudad Juarez, a stone’s throw from El Paso, was a virtual killing zone.Obama approved an intensification of bilateral measures. Deputy national security adviser John O. Brennan, also in charge of counterterrorism operations focused on al-Qaeda, led the U.S. side. His Mexican partner was CISEN director Valdes.“We got people together to define the operations,” Valdes said in an interview here. Every new program was vetted by Mexico’s security team and often by Calderon. The day-to-day operations were conceived in Mexico and approved by the U.S. ambassador at the time, Carlos Pascual, and the specific Mexican agency head involved.The first important decision was to use the same “high-value target” strategy that had been so successful against al-Qaeda in Iraq and Afghanistan. U.S. authorities used real-time intelligence against kingpins on a Mexican-U.S. priority list — including cellphone geolocation, wiretaps, electronic intercepts and tracking of digital records — to help Mexican authorities target them.The second was to clean up the Mexican units that would be responsible for carrying out raids.As early as 1997, the DEA had funded the creation of Sensitive Investigative Units (SIU) made up of foreign nationals, first in Colombia, then in Bolivia, Peru and Mexico, and eventually in nine other countries. By mid-2006, the DEA had two units with a total of 184 members in Mexico alone, according to a DEA inspector general’s report. The Mexicans were brought for training to the DEA’s facility at Quantico.Mexico does not allow U.S. agents to take part in the actual raids, but they can be involved in planning operations and can even direct them remotely.The CIA also has trained units in raid tactics, protection of senior officials, intelligence collecting and, in a departure for the spy agency, in gathering and preserving evidence that can be used in court.To guard against penetration from the cartels, members were polygraphed, drug-tested and vetted for criminal and financial irregularities. But operations were still routinely exposed by moles inserted by the cartels. So, beginning in 2009, the size of the units was cut significantly. Those who remained worked under cover and lived in secret safe houses. The U.S. agencies they worked with provided special cellphones and even paid their salaries and set up their bank accounts. There are now six or seven SIUs in Mexico, sponsored by the DEA, CIA and at least one other U.S. law enforcement agency.The two countries also have constructed an elaborate physical infrastructure and developed protocols for sharing sensitive, often real-time intelligence. Garza, the former U.S. ambassador, called it “the plumbing” of the security relationship.