* Main producing states to contest bill in courts
* Former vetoed articles of bill to affect current contracts
* Veto overturn a defeat for President Rousseff
BRASILIA, March 7 (Reuters) - Brazil's Congress has overturned a presidential veto of a controversial oil and natural gas royalty bill, stripping billions of dollars in revenue from producing states, which have threatened to contest the bill in the courts.
While originally aimed at giving non oil-producing states a fair share of Brazil's future oil wealth, the new law cuts the share of oil royalties also received from existing production contracts by states and cities bordering maritime fields and redistributes the income among all 27 states and 5,500 municipalities.
By altering existing oil contracts, the new law risks poisoning future debates with states over tax reform and mining. The law could create fresh uncertainty for oil companies operating in Brazil as well, and delay the South American nation's plans to tap huge subsalt fields and become a major world oil producer.
The result of the vote announced on Thursday was a defeat for President Dilma Rousseff, who had committed herself to limiting the immediate impact of her government's oil industry reform on producing states led by Rio de Janeiro. One of the most divisive issues of her 2-year-old presidency, the issue has soured relations among Brazil's states.
"The royalty issue has become a zero-sum game, there are clear winners and clear losers and the losers are not happy," João Augusto de Castro Neves, a senior analyst with the Eurasia Group in Washington in an interview.
"The producing states' defeat may contaminate other issues such as Rousseff's push for a new mining code or lead them to block efforts for tax reform," Castro Neves, an economics and energy specialist, said.
The governments of Rio de Janeiro and Espirito Santo along with Sao Paulo state, where offshore oil production is starting to grow rapidly, say they plan to go to the Supreme Court to challenge the law.
Approved by Congress in November, the bill was vetoed in part by Rousseff under rules that give Brazil's president the right to a line-item veto, removing sections of a bill while passing other parts.
Congress left intact Rousseff's contribution to the new law that 10 percent of all future oil royalties be used to fund improvements in education in Brazil without which, she said, the country's development will be hobbled.
Rio de Janeiro has said it could lose as much as 3.1 billion reais in 2013 alone under the new law, undermining plans to host the World Cup soccer tournament games in 2014 and the Olympics Games in 2016.
Rio de Janeiro and neighboring Espirito Santo received 86 percent of all oil and gas royalties and windfall profits taxes given directly to states and municipalities in 2012, according to Brazil's oil regulator, the ANP. Most controversially, the new law cuts the states' and municipalities' share of royalties on existing oil-production concessions.
Total royalties and windfall profits taxes in 2012 were 31.6 billion reais ($16.1 billion), with about half going to the federal government and the rest directly to states and municipalities.
Rio de Janeiro's Governor Sergio Cabral and his supporters said last year that they hope the Constitution's restrictions on the extinction of existing rights will protect their previous share of royalties on existing production contracts, limiting the changes to future oil production.
Under the law, producing states' royalties will shrink to 20 percent of the total royalty take by 2019 from 40 percent today. Producing municipalities share will drop to 4 percent in 2019 from 10 percent of the total take today.