Iraq's parliament has elected the moderate Kurdish politician Barham Salih as president.

Mr Salih, a member of the Patriotic Union of Kurdistan (PUK), beat his main rival Fuad Hussein, of the Kurdistan Democratic Party's (KDP), by 219 votes to 22, AFP news agency reported.

The post of president in Iraq is largely ceremonial.

According to a power-sharing deal, top government roles are divided between Iraq's predominant ethnic groups.

Since 2003 the president has always been a Kurd, while the prime minister is a Shia Muslim and the parliamentary speaker is drawn from the Sunni Arab bloc.

"I promise to safeguard Iraq's unity and safety," Mr Salih, 58, said during his swearing-in ceremony.

Mr Salih was part of the interim government put in place by the US following the 2003 invasion that ousted Saddam Hussein.

He went on to become deputy prime minister under Nouri Maliki and also served as prime minister in the Iraqi Kurdistan regional government.

However, Mr Hussein's main backer, KDP leader Massoud Barzani, said his party rejected the parliamentary vote as there should have been a single Kurdish candidate for the presidency.

He said the candidate should have come from the KDP as it was the largest Kurdish party.

Mr Barzani was the architect of last year's referendum on independence for Iraqi Kurdistan. More than 90% of Kurds who took part in the ballot supported independence but Iraq's Supreme Court ruled it unconstitutional.

Following that vote, the Iraqi government seized disputed territory including the oil-rich province of Kirkuk.

Mr Barzani later resigned as regional president.