(Adds detail, background)
KHARTOUM, July 11 (Reuters) - Sudan's military rulers said on Thursday that several officers had attempted a coup in an effort to undermine an agreement between the military and the opposition to share power for three years ahead of elections.
The thwarted coup involved a number of retired officers as well as officers still in service, Jamal Omar Ibrahim, the head of the Transitional Military Council's security committee said on Sudanese TV.
He added that 12 had been arrested and four detained in connection with the thwarted coup.
The military council and a coalition of opposition and protest groups agreed provisionally last week to share power for three years, bringing thousands onto the streets to hail a first step towards ending decades of dictatorship.
The deal has revived hopes for a peaceful transition of power in a country plagued by internal conflicts and years of economic crisis that helped trigger months of protests, which ended Omar al-Bashir's 30-year rule in April.
The agreement has yet to be finalised and signed.
Relations between the military council that ousted Bashir in a coup and the Forces for Freedom and Change opposition alliance broke down when security forces killed dozens as they cleared a sit-in on June 3. But after huge protests against the military, African mediators brokered a return to direct talks, which led to the deal. (Reporting by Alaa Swilam, writing by Lena Masri Editing by Susan Thomas and Sanfdra Maler)