Diplomatic observers here were puzzled over the failure of Turkey’s bid to become a non-permanent member of the UN Security Council, despite its excellent credentials for the task.

Turkey, considered an ally of the United States, lost out to Spain and New Zealand in a contest for two available seats reserved for a bloc called the Western European and Others Group, which includes the United States.

These observers pointed out that Spain is one of Europe’s perennial economic trouble spots, and New Zealand is a geographically isolated island nation of 4.5 million people. Turkey, on the other hand, is a rising superpower, a NATO member with the world’s 17th-largest economy along with a sizable and advanced military. Its leaders have even pushed for reforming the Security Council in a way that would reflect the ascendancy of emerging powers like Turkey.

While campaigning for the seat, Turkey highlighted in particular its role in the war against the Islamic State extremist group. But Turkey has also come under scrutiny, particularly by European countries, for what critics call its insufficient crackdown on foreign fighters who have travelled through Turkey to join extremist groups in Syria.

Some analysts said Turkey’s defeat also reflects the divisions in the Middle East, as Egypt, Saudi Arabia, Iran and others jostle for power.

In the past few days, according to several diplomatic sources, there was an intense campaign, led by Egypt and Saudi Arabia, against Turkey’s membership in the council. The two countries are angered by President Recep Tayyip Erdogan’s support for the Muslim Brotherhood, which both are fighting at home.

Syria, as well as its ally Iran and several others, are also peeved by Erdogan’s frequent calls to unseat Syrian President Bashar Assad. Several Western countries expressed  alarm by recent reports of Turkish attacks on Kurds fighting ISIS in Syria. And Turkey’s traditional opponent, its neighbour Greece, is also said to have lobbied against its election to the UN’s most prestigious body.

“It’s surprising, because I was told just days ago that Turkey received letters of support from 160 countries,” said one informed source after the secret ballot ended in Turkey’s failure to edge out Spain. The source noted, however, that Spain received 154 letters of support from the 193 General Assembly members. “This isn’t the way this should be done,” said the source, referring to the habit among member states of expressing support publicly while opposing membership in secret balloting.

Turkey’s foreign minister, Mevlut Cavusoglu, rose from his seat as soon as the results were announced and walked over to congratulate his counterpart from Spain. On Twitter, he congratulated all five victors. The Foreign Ministry’s Twitter handle said nothing about the results.

Anadolu, the semi official news agency, quoted the foreign minister as saying: “There may be some countries disturbed by our principled stance, and there have always been those, who, after some time, confess that Turkey’s position was right. So, we could not abandon our principles for the sake of getting more votes.”

There were also three uncontested seats in the Council race. Angola was chosen by the nations of Africa to represent the continent, starting in January 2015. Malaysia was selected as Asia’s candidate, and Venezuela was picked to represent Latin America.

Venezuela’s win this time comes after the late President Hugo Chavez’s 2006 bid for a council seat was thwarted by the US The Obama administration didn’t publicly oppose the bid under Chavez’s successor Nicolas Maduro.

Chavez’s daughter will represent Venezuela in the council chambers as a senior diplomat to the UN.

To win, each country had to obtain support of two-thirds of the General Assembly members present at the vote, or a minimum of 129 votes if all 193 members vote. New Zealand won 145 votes in the first round, and Spain topped Turkey 132 to 60 in the second round of a run-off vote.

Observers recalled that one of the most intense contests for a seat on UN’s high table was in 1975 when Pakistan challenged. With Pakistan’s prestige in the comity of nation at its peak, the then Prime Minister, Zulfikar Ali Bhutto, joined the contest after his Indian counterpart Indira Gandhi announced India’s  bid to seek membership of the Security Council. As voting started in the Gneeral Assembly, both countries were short of the required twothird majority, although Pakistan had more vote. Pakistan’s vote continued to grow in subsequent ballots, and in the eighth round Pakistan was just four votes short of the target while India was way back. At this stage, India was urged to withdraw by several member states and it bowed out. At that time, Pakistan was still in CENTO and SEATO security pacts, while India was a leader in the Nonaligned Movement (NAM), a 125-member body with huge influence in international politics. Still, with a well-executed plan.

Observers recalled that one of the most intense contests for a seat on UN’s high table was in 1975 when Pakistan challenged India.