In simplest terms, the aircraft appears to have been engaged in a heading mode, instead of following the programmed navigation course. As a result it drifted north of course and well into Russian airspace, then exiting that airspace before being attacked.
As with many accidents it is not quite a simple as that.
Tensions were high in the cold war era. The Russians were fearful of a first strike nuclear attack by Reagan. In light of the "star wars" initiative, placing of Pershing II missiles in Europe, and large scale fleet exercises in the North Pacific it was not an entirely unreasonable fear. There were plenty of Americans afraid of the same thing! The US had been flying reconnaissance missions near Russian territory and even over Russian military installations. This had resulted in the dismissal or reprimanding of Soviet military officials who had been unable to shoot them down.
There was also a heightened alert around the Kamchatka Peninsula at the time KAL 007 was in the vicinity, because of a Soviet missile test that was scheduled for the same day. A US Air Force RC-135 reconnaissance aircraft (another four-engine Boeing) was flying in the area was monitoring the missile test off the peninsula. The Russians were not happy.
While tracking KAL 007 on radar, Russian generals argued whether they needed to first be sure it was not a civilian airliner. The pilot performing the shoot down, knew that it was a passenger-type plane, but did not question his orders. After all, couldn't a 747 with windows and a civilian paint job be easily equipped as a spy plane? The intercepting pilot later recalled "I did not tell the ground that it was a Boeing-type plane; they did not ask me."
An out of service Soviet radar, limited range of the intercepting aircraft, and other command and control problems complicated the issue.
The intercepting aircraft shot over 200 warning rounds. But in the 1991 words of the lead Su-15 pilot who fired warning shot:
“I fired four bursts, more than 200 rounds. For all the good it did. After all, I was loaded with armor piercing shells, not incendiary shells. It's doubtful whether anyone could see them..."
Also contrary to international procedures, the airliner was not contacted on the 121.5mHz emergency frequency. A frequency that all aircraft should have/would have been monitoring over international waters.
The missile strike that took down the aircraft did not destroy it in flight. It exploded close behind the 747, severing control cables and hydraulic lines, and depressurizing the aircraft. The engines remained operational. The aircraft pitched up despite forward control column inputs and climbed from 35,000 to 38,000 before descending and eventually spiraling into the sea below.
Information about what really happened was hard to come by and took many years to arrive at the current version - which may still not be the full truth. After all, egos and international pride are always at stake in these types of confusing incidents.
A more conspiratorial version is covered in Michael Brun's book "Incident at Sakhalin: The True Mission of KAL Flight 007." The title is a bit provocative of a point the author actually doesn't make. The book is extensively researched, the author having personally combed the beaches of the sea. The book tells an alternate story of a air battle where 10 or more US aircraft were shot down, killing 30 or more US Air Force and Navy personnel. Needless to say the author's conclusions are not without some disagreement. It is certainly an interesting read, nonetheless.
But it is not just "evil empires" that shoot down civilian airliners. The "good guys" have screwed up too, as when the USS Vincennes shot down Iran Air flight 655 in July 1988, thinking the Airbus A300 was an F-14. According to the Wikipedia article, the United States has never admitted responsibility, nor apologized to Iran, though a settlement for passenger damages was reached.
It seems that international tensions are high virtually all of the time in at least some part of the world. Of course, this week it is the Syrians who are fearful of an imminent American attack. Once again, many Americans are also dreading the possibility of those fears being realized.
Yet, despite the tensions, airlines of many nations continue to operate near these areas. Their crew and passengers often unaware of military and political egos, and nervous trigger fingers. There were no NOTAMs telling the KAL007 crew that they could be mistaken for a spy plane, the Iran Air 655 crew they could be mistaken for an F-14, and there isn't one now warning crews they could be mistaken for a cruise missile.
Careful navigation and close adherence to procedures remain essential, but cooler heads in international politics may be one of the most essential elements to international air safety.