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

The Canadian company declined to make an immediate 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 had threatened to ban the Messenger service last Friday before giving RIM until Monday as it worked with local firms testing servers.

The source familiar with the negotiations told Reuters that idea -- setting up a server at each of the three local service providers - had proved impractical.

As a result, the firm has agreed to offer Saudi Arabia's interior ministry and intelligence services the codes to all Saudi BlackBerry users, said the source, declining to be identified.

A spokesman for the Saudi regulator was not available for immediate comment.

(Reporting by Souhail Karam; Editing by Jason Neely, Greg Mahlich)