BlackBerry maker Research In Motion has agreed to hand over coveted codes to users' phones to try to avert a ban on its Messenger service in Saudi Arabia, an industry source familiar with the talks told Reuters on Tuesday.

The Canadian company declined to comment, referring media to its earlier statement in which it said: RIM cooperates with all governments with a consistent standard.

The biggest BlackBerry market in the Gulf with 700,000 users, Saudi Arabia threatened to ban the Messenger service on Friday before giving RIM until Monday as it worked with local firms testing servers.

Saudi Arabia, like neighbors United Arab Emirates (UAE), Kuwait and others including India, has expressed concern that BlackBerry's encrypted messaging could be used to harm social and national security interests.

The BlackBerry has proven popular with young singles in Saudi Arabia as a means of meeting in an Islamic society which restricts contact between unrelated men and women.

Activists in the Gulf region have also said its encrypted texting has helped foster freer dialogue, including criticism of governments and policies.

The Saudi regulator said earlier the Messenger service was working as there had been progress in working with RIM, but the source familiar with the negotiations told Reuters the solution that RIM was working on -- setting up a server at each of the three local service providers -- had proved impractical.

As a result, the company has changed course and will now offer Saudi Arabia's Interior Ministry and intelligence services the codes to all Saudi BlackBerry users, said the source, declining to be identified.

EMIRATES

In light of the positive developments in completing part of the regulatory requirements from the service providers, the regulatory authority has decided to allow the continuation of the BlackBerry Messenger services, the Saudi regulator had said earlier.

The Communications and Information Telecommunications Commission said it would continue working with the service providers to complete the rest of the regulatory requirements.

The source said the agreement with Saudi Arabia would mirror data processed by RIM's main server in Canada.

Each BlackBerry user registered with the three Saudi mobile operators has a PIN number, and for each PIN number RIM has a code.

A spokesman for the Saudi regulator was not available for immediate comment on the source's remarks.

RIM co-CEO Michael Lazaridis told the Wall Street Journal last week that the firm would have to comply if faced with a court order to intercept communications.

I would give them the encrypted stream, he said. It would have to be like a wiretap.

Abdulhamid al-Amri, a member of the Saudi Economic Association, said things will go back to normal once the problem was solved.

I believe that the firm (RIM) will be as responsive to the rest of the countries because it is in its interest not to play favorites between countries as that would affect its own interests, he said.

Even if RIM and the Saudi regulator reach a firm agreement, the company still faces a more sweeping ban set for October in the neighboring UAE. Authorities there have threatened to ban Messenger as well as emailing and web browsing on the device.

BlackBerry, unlike rivals Nokia and Apple, operates its own network through facilities in Canada and Britain.

Top Saudi operator Saudi Telecom Co and rival Mobily were not immediately available for comment.

(Additional reporting by Alastair Sharp in Toronto; Writing by Jason Neely; Editing by Greg Mahlich and Alison Williams)