By Alexei Anishchuk

BRASILIA (Reuters) - Brazil agreed on Wednesday to negotiate the purchase of Russian anti-aircraft missile batteries on the condition that Russia transfer the technology to Brazilian defense companies without restrictions.

The agreement was announced after Russian Prime Minister Dmitry Medvedev met with Brazilian President Dilma Rousseff on a visit to Brazil to advance defense, energy and agricultural deals with a fellow member of the BRICS bloc of emerging nations.

Brazil is beefing up its air defenses before the World Cup soccer tournament next year and the 2016 Olympic Games to ward off the threat of a terrorist attack during the global sporting events, which will draw massive crowds of foreigners.

Brazil is interested in buying medium-range surface-to-air Pantsir S1 combined missile and artillery batteries and Igla-S shoulder-held missiles, as well as acquiring the technology to build the weapons itself in the future.

Contract negotiations will begin in March, the governments said in a signed statement that called for the effective and unrestricted transfer of technology to Brazilian defense companies. No values were mentioned.

The Chairman of the Joint Chiefs of Staff of the Brazilian Armed Forces, General Jose Carlos de Nardi, said the contract would be signed in three months and the batteries would arrive in Brazil in time for the Olympics, but not the World Cup.

"The Olympic Games are a bigger defense concern because they take place in different locations of one city, while the World Cup is just one stadium in several cities," he told Reuters.

ENERGY ALLIANCE

Medvedev's trip follows a visit by Rousseff to Moscow in December that underlined the importance both countries attach to building relations among BRICS countries.

The BRICS - Brazil, Russia, India, China and South Africa - account for one quarter of global GDP and 40 percent of the world's population. They have become increasingly vocal in criticizing developed nations' hold over international economic policies.

Ties between Brazil and Russia have been strengthening and Medvedev said the two countries aim to raise annual trade turnover to $10 billion from the current $6.5 billion.

Russia is touting its advanced energy expertise and technology to open business opportunities in Brazil's oil and gas industry. It also hopes to get involved in Brazil's plans to build new nuclear power stations to meet surging demand for electricity that has overwhelmed its generating capacity.

"An energy alliance would benefit our people and our companies," Medvedev said.

Brazilian officials said Medvedev's visit advanced talks to eliminate sanitary hurdles that are slowing Brazil's meat sales to Russia, its largest buyer.

As a sign of the two countries drawing closer, Brazil on Tuesday became the first country outside Russia to host a monitoring station for the Russian satellite navigation system GLONASS, a global positioning system that uses 24 satellites.

(Additional reporting by Anthony Boadle and Peter Murphy; Editing by Doina Chiacu)