The castle which provided the venue for the first National Eisteddfod more than 800 years ago has been bought for use by the public.
A cultural centre is to be developed on the site
Ceredigion County Council has paid around £500,000 for Cardigan Castle and now plans to carry out repairs and develop it as a national cultural centre.
The 12th century castle has been the focus of a local campaign to ensure its future with 3,000 people supporting a petition calling for it to be saved from dereliction.
Two years ago its long-term owner, 86-year-old Barbara Wood, who now lives in a residential home, put the castle up for sale for more than £1m.
I am delighted with the sale because the castle will now come into the public domain so that the people of Cardigan and the world can enjoy it
Nicolas Rees, estate agent
Potential buyers had to consider the estimated £8m it would cost to restore the two acre site.
But now contracts have been exchanged with the local authority who will officially become the castle's new owner when completion takes place on 14 April.
Estate agent Nicolas Rees of Fred Rees and Son, handled the sale of the property.
"I am delighted with the sale because the castle will now come into the public domain so that the people of Cardigan and the world can enjoy it," said Mr Rees.
Ceredigion county councillor John Adams-Lewis said he was pleased the property had not fallen into private hands.
"The council can now develop the site with a project that will be important for Cardigan's future."
A campaign was mounted in the town to save the castle
The council had previously threatened to issue a compulsory purchase order for the castle.
Tim Ball, the council's head of planning, said consultants were being commissioned to draw up a business and conservation plan to restore the castle.
He added that the first step would be to restore Castle Green House - a 20-room Georgian House which stands inside the castle walls.
"It will take about 10 years to complete the whole work which could cost about £8m in total."
Built in 1171 by Rhys ap Gruffydd on the southern edge of Cardigan, the castle was the site of the first National Eisteddfod five years later
It fell into the hands of the Normans in the 13th century who carried out extensive repairs.
But the castle was no longer used as a fortification after it was attacked by Cromwell's army in the mid 17th century.