Twenty-five years ago this week tumultuous scenes were unfolding in the East German city of Dresden: inside the central station, tens of thousands of people clashed violently with police, army and Stasi forces. And the chances are high that a 36-year-old KGB officer named Vladimir Vladimirovich Putin would have followed the chaos with his own eyes.

The story of what happened in Dresden on 4 October was soon overshadowed by the peaceful fall of the Berlin Wall a month later. Yet understanding what Putin the KGB officer may have seen that day could hold the key to understanding how the Russian president sees the crisis in eastern Europe today. For someone who believed deeply in the cold war order, it was most likely an excruciating experience. It is clear that he returned home soon afterwards in disgust, full of bitterness that lingers to this day, with dramatic consequences. Thanks to surviving evidence from police, Stasi, and party files, as well as interviews, it is possible to trace Dresden’s descent into chaos over the course of 1989.

By late summer in 1989 it was apparent that East Germany’s regime of hardliners, headed by Erich Honecker, was never going to follow the example of the Soviet leader, Mikhail Gorbachev, and reform. As far as Honecker was concerned, the iron curtain should stay closed. But over the course of that summer the Hungarians had eased their border controls, and a massive wave of East Germans had rushed southwards to the border between Hungary and Austria to try to escape to the west: by mid-August, more than 200,000 East Germans were making their way through Hungary.

When Honecker forbade East Germans from travelling to Hungary, agitated refugees flooded the grounds of the West German embassies in Warsaw and Prague. About 5,000 crowded on to embassy grounds, huddling in the mud as cold, damp autumn weather arrived.

The situation rapidly became so desperate that East and West Germany brokered a deal: the refugees could go west, but on Honecker’s insistence they could do so only on sealed trains (a means of transport with tragic historical significance in Germany) that passed through East Germany first. After recording their names, Honecker would then prove that he was boss by “expelling” them to West Germany – all the while they stayed on the same trains. On the night of 30 September about 5,500 East Germans made it to West Germany via this bizarre route. Honecker then closed the East German borders entirely, thus putting an end to the refugee problem once and for all – or so he thought.

Inside East Germany, just south of Dresden, more would-be refugees were stuck on the southern borders of their unloved state. Instead of going home, they started protesting in large numbers. And more East Germans managed to reach the Prague embassy before the borders were fully sealed. As a result Honecker had to allow more trains from what was then Czechoslovakia to West Germany, scheduled to roll through the centre of Dresden on 4 October.

With the borders now closed, this second set of overflowing trains became known as the “last trains to freedom”, and everyone wanted a ticket: 2,500 people flooded Dresden’s main railway station, blocking the tracks in the hope of getting on board; another 20,000 packed the area outside. For hours, the blockage forced the trains to wait south of the city centre. Panicked, the East German leaders contacted their Czech comrades, asking them to take the trains back, but Prague refused.

So the Dresden police and Stasi decided to fight through the night to clear the station. More than 400 East German soldiers, armed with machine guns, were sent to the city as well. Stasi files record that 45 members of the East German security forces were injured and at least one police car was turned over and set on fire. Protesters later recounted multiple incidents of police brutality, both on the streets and at hastily organised detention centres. It took until the early hours of 5 October to get at least three of the trains through. The rest had to be re-routed through other cities.

Dresden helped to set in motion a chain of events that would lead to the fall of the wall. One of Gorbachev’s senior aides, Anatoly Chernyaev, lamented the spread of “terrible scenes” of violence, damaging to the East German and Soviet regimes alike. The images worsened the split between Gorbachev and East Berlin, rendering them less capable of coordinated action in the face of protests.

Opposition leaders, for their part, made heroic efforts to guarantee that future protests would be nonviolent. They succeeded: when, on 9 October, dissidents squared off against state security forces in Leipzig, the sheer numbers cowed the state’s security apparatus without violence. The resistance movement then rolled northward over the entire country, eventually toppling the East German regime and the Wall.

It is impossible to say with any certainty where Putin was during these events. He made sure he covered the tracks of his German posting by burning documents, partly to prevent them from falling into the hands of protesters.

But it is clear that he spent much of the late 1980s in East Germany as a member of the Soviet secret police, and there is no reason to think he was absent that October. Putin himself has recalled to interviewers in vague terms how he watched events unfold: it is a reasonable assumption that he saw crowds seize control in Dresden first hand.

This event was a catastrophe from the point of view of Soviet loyalists, and few were more loyal than Putin. He would later call the collapse of the Soviet Union and its authority in eastern Europe the greatest tragedy of the 20th century. Since he witnessed it with his own eyes, he has presumably never forgotten the experience.

The Dresden disaster must have had an enormous impact on him – and understanding that may help us to understand his actions today. Political scientists such as Alexander George have long theorised that world leaders function according to an internal “operational code” acquired during younger, formative years, which they then rely on to guide them years later when in power.

The events of 4-5 October 1989 may very well have helped to shape Putin’s operational code. His swift and aggressive responses both to the popular uprising in Kiev earlier this year and to the earlier demonstrations in Moscow suggest that they did. He saw the crowds seize control – and is not, to put it mildly, comfortable with that precedent.

This analysis does not bode well for the future of the Ukraine crisis. The conflict in Ukraine, and the resulting wounds to relations between the west and Moscow, will fester as long as Putin remains in power, for operational codes rarely change once set. Having witnessed protesters first get the better of local authorities and then distant rulers, he will do whatever he deems necessary to prevent the same scenario from repeating itself.