BAKU, Azerbaijan (JTA) — With less than a month to go until presidential elections, the moustachioed smile of Ilham Aliyev stares down at his countrymen from giant posters scattered around this bustling metropolis on the Caspian Sea.

The Azerbaijani president has been in office since 2003 and is widely expected to be re-elected, extending the leadership of the Aliyev clan into its third decade. Aliyev’s father, Heydar, held the post for a decade prior to his son’s ascension.

Ilham Aliyev’s tenure has brought greater prosperity to this young country, but it has come at a price: Widespread corruption and human rights abuses have earned Azerbaijan a dismal ranking in a survey of democratic standards in 166 countries conducted last year by the Economist magazine.

But to the West — especially to Israel — Aliyev is a trusted friend and the key to a transformation that has developed oil-rich Azerbaijan from a small nation in Iran’s shadow to a strategic ally and an avid consumer of Israeli arms.

“The partnership between Israel and Azerbaijan is complicated by political factors, but ultimately it is moving forward because it makes sense from an economical point of view,” said Oded Eran, a former Israeli ambassador to the European Union and ex-director of Israel’s Institute for National Security Studies. “Azerbaijan is reliable enough as a supplier of oil for Israel, and Israel is a reliable supplier of high-tech and arms.”

Israel has long cultivated ties with this Muslim nation, which has enormous reserves of oil and natural gas and a 380-mile southern border with Iran. The Jewish state opened an embassy in Baku in 1992, just one year after Azerbaijan gained independence from the former Soviet Union.

But Azerbaijan, mindful of antagonizing its neighbor, the partnership has mostly flourished in the shadows. Azerbaijan still does not have an embassy in Israel, despite expanding bilateral trade now pegged at $3 billion a year. In 2009, Aliyev compared relations with Israel to an iceberg: “nine-tenths submerged.”

The elder Aliyev, a former KGB boss, handled the relationship with Israel “with great care during those early and unstable times,” according to Avinoam Idan, a senior research fellow at John Hopkins University’s Central Asia-Caucasus Institute.

In recent years, however, the partnership has grown much more open — and more robust.

In 2011, the Israeli defense contractor Aeronautics opened a factory for military drones in Azerbaijan. The following year, the state-owned Israel Aerospace Industries sold Azerbaijan $1.6 billion worth of weapons — a deal that amounted to 43 percent of Azerbaijan’s total expenditure on arms in 2012. Azerbaijan now supplies a whopping 40 percent of Israel’s oil consumption.

In May, Elmar Mammadyarov became the first Azerbaijani foreign minister to visit Israel. Mammadyarov met with Prime Minister Benjamin Netanyahu and President Shimon Peres along with a dozen other ministers and promised that the opening of an Azerbaijani embassy was “just a matter of time.”

Israel’s increasingly cozy ties with Azerbaijan have grown in the wake of a crisis in the country’s relations with Iran. Though traditionally mistrustful of the Islamic Republic’s penchant for exporting revolutionary zeal, Azerbaijan had strived to maintain good relations, signing a non-aggression pact with Tehran in 2005.

But relations deteriorated in 2009 after Iran cracked down on the large minority of ethnic Azerbaijanis living in Iran. When Azerbaijan protested, Iranian officials threatened to raise territorial claims.

Israel was named as a factor in the dispute last year when Azerbaijani officials revealed plans by local extremists, aided by Iran, to blow up the Israeli and American embassies in Baku.

Also last year, Iran accused Azerbaijan of helping Israel assassinate Iranian nuclear scientists and gather intelligence. The situation was inflamed further by a Reuters report that Israel planned to use Azerbaijani airfields in the event of a strike on Iranian nuclear facilities.

Israeli and Azerbaijani officials denied the report.

“These reports sound like James Bond stories, and that’s exactly what they are,” said Raphael Harpaz, Israel’s ambassador to Azerbaijan, at his office at the Hyatt Regency Hotel.

That said, “Azerbaijan has taken a courageous stand against efforts to destabilize the region,” Harpaz added — an obvious reference to Iran.

Harpaz said anti-Semitic sentiment, prevalent in much of the Muslim world, is virtually nonexistent in Azerbaijan, a secular country with guaranteed freedom of worship and — unlike its abstemious southern neighbor — teeming with bars and nightclubs where scantily dressed women dance to Turkish and Russian pop hits.

“Azerbaijan’s economic success and relatively liberal attitudes form a contrast with Iran’s restrictive policies and a viable alternative, which is probably making the Mullah regime uncomfortable,” Idan said.

Despite Baku’s attempts to keep the peace, American diplomats believe Azerbaijan considers Iran “a major, even existential security threat,” according to an assessment in a leaked diplomatic cable from 2009. The country’s cooperation with Israel “flows from this shared recognition,” the cable read.

Idan says Azerbaijan’s closeness with Israel is actually aimed at a different regional foe: Armenia, Azerbaijan’s neighbor to the west, against whom Azerbaijan has fought two wars in the last century over the disputed Nagorno-Karabakh region.

Aliyev considers the conflict unfinished, which has led to American and European reluctance to sell him weapons he can’t obtain elsewhere. Israel has no such qualms.

Israel, too, may have broader reasons for cultivating ties with Azerbaijan. The Jewish state has long sought out non-Arab moderate Muslim nations as allies as a counterweight to the hostile Muslim nations that surround it.

Eldar Mamedov, an Azerbaijan-born political adviser at the European Parliament in Brussels, wrote in January that Israel sees Azerbaijan as a replacement for Turkey, whose once-close partnership with Israel hasn’t recovered from the 2010 storming by Israeli commandos of a Turkish ship bound for Gaza.

But Fuad Akhundov, a historian and government spokesman, told JTA that personal bonds between Jews and Azerbaijanis over the centuries has helped cement the bond.

“Jews here have always been perceived as promoters of progress, part of the elite, as something which holds potential,” Akhundov said. “These positive feelings had a role in the establishment of warm bilateral ties.”