The text calls for Madrid and London to reach a definitive solution to the status of the Rock, "listening to the interests and aspirations of Gibraltar that are coherent and legitimate in accord with international law," Spain's top diplomat said.
The parties expect to see the declaration become a UN General Assembly resolution.
A territory of 5.5 sq km at the entrance to the Mediterranean Sea, Gibraltar has been held by Britain since 1704 and became a British Crown Colony in 1713 under the Treaty of Utrecht.
Madrid says Gibraltar should be reincorporated into Spain, an outcome Gibraltarians have rejected overwhelmingly in referendums, while Britain maintains that the views of the Rock's residents must be taken into account.
On taking office, the current conservative government in Madrid repudiated the 2004-2012 Socialist administration's policy toward Gibraltar, which revolved around a tripartite forum that placed the Gibraltarians on equal juridical footing with Spain and Britain.
That forum "no longer exists and should be replaced by a new mechanism of local cooperation," Garcia-Margallo said Tuesday. "Now we have begun to put the toothpaste back in the tube."
The joint declaration envisions the creation of ad hoc groups to deal with specific issues, he said.
Those groups will include representatives of Spain, Britain, Gibraltar and the neighbouring southern Spanish region of Andalusia, according to the foreign minister.
Tension between Madrid and London over Gibraltar flared in July when the local administration on the Rock dropped 70 concrete blocks into the Mediterranean with the aim of forming an artificial reef.
The reef project violates the European Union's environmental regulations and threatens the livelihoods of Spanish fishermen, according to Madrid, which imposed new border checks that have led to hours-long waits for people entering and leaving Gibraltar.