In 2010 there were 270 persons killed in traffic accidents in Sweden. Per capita this may be the lowest number in the world. Per capita, it is the lowest number in Sweden for more than 90 years. In the 1960's, when we were fewer and had fewer cars there were 2000+ deaths per year, so this is a really huge improvement in safety. Some of the post-2000 improvement may be due to us driving a shorter total distance, but not the last years'. And the number of people requiring hospital care has also been reduced, so the figures are not just due to improved medical care.
However: There is one category which haven't gotten a safer traffic: Cyclists.
And regarding railways, safety hasn't gotten better. Only one passenger died in 2010, but 108 other persons. A significant part of them probably because they wanted, but not all.
So the trend is that technology makes for safer transport and there's not much technology available to prevent people from stopping their vehicles on tracks (there can be detectors for cars on a railway crossing which does help a bit) or standing on tracks. Apart from fences, but that's not a practical solution in Sweden.
In short: We don't behave safer, but we're given more safety anyway.