Factbox-South Africa's Ramaphosa re-elected president. What happens next?

First sitting of parliament in Cape Town

By Nqobile Dludla

JOHANNESBURG (Reuters) - Cyril Ramaphosa was re-elected as South Africa's president on Friday with the support of once rival parties that have agreed to join his African National Congress (ANC) in a new government of national unity.

The ANC - which was forced to share power for the first time in 30 years after losing its majority in last month's vote - still has to work out how to divide up the top cabinet jobs and overcome ideological differences with its new partners.

Here is what has happened and what to expect next:

WHAT HAS HAPPENED?

Just a few hours after the first session of the new parliament got underway on Friday, the white-led, pro-business Democratic Alliance (DA) announced it would co-govern with the ANC "in a spirit of unity and collaboration".

Two smaller parties, the socially conservative Inkatha Freedom Party and the right-wing Patriotic Alliance, are also part of the pact.

The Marxist Economic Freedom Fighters (EFF) party said it will not be part of a government that includes the DA or the Freedom Front Plus - two parties that draw support from the white minority.

The uMkhonto we Sizwe (MK) party, led by former President Jacob Zuma, is also not part of the unity government.

MK, which came in a surprising third in last month's vote, has said it will join an alliance of smaller opposition parties in parliament called the "Progressive Caucus", which includes the EFF and the centre-left United Democratic Movement.

This alliance will be the official opposition to the coalition government.

PARLIAMENT ELECTS PRESIDENT

On Friday, lawmakers took their oaths of office at the first session of the 400-seat National Assembly since the May 29 vote, then elected the ANC's Thoko Didiza as speaker and DA member Annelie Lotriet as deputy speaker.

Ramaphosa was elected by lawmakers for a second term in office. He was going against EFF leader Julius Malema.

Since the ANC fell short of a majority, Ramaphosa drew upon the support of his new political allies to retain the presidency.

Under South African law, candidates for president, speaker and deputy speaker of the National Assembly are nominated by members of parliament. If only one candidate is nominated, he or she is then elected.

In the case of multiple candidates, lawmakers cast secret ballots with a candidate requiring support from a majority of members to be declared the winner.

INAUGURATION OF THE PRESIDENT

Ramaphosa will be sworn in at an inauguration ceremony on Wednesday, June 19. He will preside over the seventh administration since the end of apartheid and the advent of multi-racial democracy.

CABINET SELECTION

The negotiations between the parties in the unity government will determine the composition of the executive branch, which is expected to undergo a major overhaul.

Political parties will negotiate conditions, including preferred portfolios, positions and cabinet candidates, which the newly elected president will announce in the days following his inauguration.

Key ministries such as finance, energy, foreign affairs and public enterprises are among the most coveted portfolios.

Prior to the election, Public Enterprises Minister Pravin Gordhan, Minister in the Presidency Nkosazana Dlamini-Zuma and Trade, Industry and Competition Minister Ebrahim Patel all indicated they planned to step down.

South African law dictates that the president, who has the sole discretion to appoint the cabinet and deputy president, may select no more than two people from outside the National Assembly.

Once the cabinet is announced, Ramaphosa in conjunction with the speaker of the National Assembly and the chairperson of the National Council of Provinces, determines a date for the Opening of Parliament Address.

This address outlines the new administration's governing priorities and marks the beginning of the new five-year parliamentary term.

(Reporting by Nqobile Dludla; Editing by Joe Bavier, Olivia Kumwenda-Mtambo and Angus MacSwan)