ANKARA - Turkey is running out of time to ratify NATO membership bids by Sweden and Finland before it holds elections expected in May, a Turkish presidential spokesman said on Saturday.

President Tayyip Erdogan's spokesman, Ibrahim Kalin, said Turkish ratification of the countries' bids depended on how quickly Stockholm fulfils counter-terrorism promises made as part of a deal with Ankara, warning that could take months.

"Stockholm is fully committed to implementing the agreement that was signed last year in Madrid, but the country needs six more months to write new laws that would allow the judicial system to implement the new definitions of terrorism," Kalin told a news conference in Istanbul.

Along with Finland, Sweden signed an agreement with Turkey last year aimed at overcoming Ankara's objections to their NATO bids, which were made in May last year and require the approval of all 30 NATO member states. Both countries applied to join NATO after Russia's invasion of Ukraine.

Ankara has said Sweden needed to take a clearer stance against what it sees as terrorists, mainly Kurdish militants and the organisation it blames for a 2016 coup attempt.

The Turkish parliament would have to ratify Ankara's decision on the two Nordic countries' membership, with a vote on both expected at the same time.

Kalin said the Swedish government needed to send a clear message to "terrorist organisations that Sweden is no longer a safe haven for them and that they will not be able to collect money, recruit members, and engage in other activities".

"We have a time issue if they want to join NATO before the NATO summit in June," Kalin added, referring to the Turkish presidential and parliamentary elections, expected in May.

"Given that the parliament will go into recess some time before the elections, you're looking at 2-2.5 months time frame to do all this," he said.

(Reporting by Jonathan Spicer Writing by Ece Toksabay Editing by Helen Popper)