By Tom Miles

GENEVA (Reuters) -- Talks between Russia and the United States may produce a chance of peace in Syria, Kofi Annan, the former U.N. secretary-general who tried unsuccessfully to forge a deal to end the war in 2012, said on Tuesday.

"In this situation the role of Russia and the U.S. are key. If the two of them find a way of working effectively together and working with the others, we will find a solution.

"No war goes on forever," Annan told a packed audience of students and diplomats, including Lakhdar Brahimi, who succeeded him as the Syria mediator, but also quit after failing to forge agreement between the warring sides.

The United States and Russia will hold talks on Syria in Vienna on Friday, and have invited Iran, which is widely seen as a key part of any peace deal but which the United States refused to have at the table when Annan was presiding in 2012.

The key to ending the four-and-a-half-year war, which has killed more than 250,000, was getting "governments who are funding the war, who are giving money and arms to the parties responsible" to work together, Annan said.

"Perhaps it was too early in 2012, maybe it wasn’t ripe. But today we see contacts that were not possible in 2012 or even a year ago, where you are seeing meetings between the Russians, the Saudis, the Americans and the Turks, trying to find a common solution."

The only way to bring peace was if the five permanent members of the U.N. Security Council, possibly working with Germany, worked together with the regional powers - Saudi Arabia, Turkey, Iran, Egypt and Qatar, he said.

Those governments would be able to rein in the armed opposition groups fighting in Syria, which would have to be part of any peace deal, he said.

"Eventually you will deal with them, you will talk to them, but you have to organize it in such a way that those who are pulling the strings, that those who have influence on them, that those who have funded the war, will come together to say ‘this is it, we’re not going to fund it any more’."

(Reporting by Tom Miles; Editing by Lisa Shumaker)