The ethnic groups of Austria-Hungary weren't fond of each other, but their hatred for Franz Ferdinand is the one thing they had in common. He once proposed a triple monarchy, which would give the Slavs an equal voice along the Germans and Magyars... but the ruling elite weren't fond of that idea. He also considered making a 16-state government, to be called the United States of Greater Austria. However, it conflicted with the Serbian nationalists.
Archduke Franz Ferdinand and his wife, Sophie, were invited to visit Bosnia in 1914. Franz was scheduled to inspect imperial troops, so he was in Sarajevo. A terrorist group called the Black Hand sent 6 assassins to kill the Ferdinand's while they toured around the city in an open-topped car.
Assassin 1: Chickened out, ran away.
Assassin 2: Threw a grenade at the Ferdinand's, which bounced off the car and injured some civilians. The assassin took a cyanide pill and threw himself into a river to avoid the police... the cyanide pill was expired, and the river was six inches deep. He was apprehended.
Assassins 3, 4, 5: Gave up.
Assassin 6: Gave up, decided to go get a sandwich. He turned around... and saw the Ferdinand's car go down the street as it had taken a wrong turn. Seizing the opportunity, he quickly drew his gun and shot both Franz and Sophie.
The assassination of Archduke Franz Ferdinand by a Serbian nationalist is considered to be one of the main causes leading up to WWI (in addition to militarism, alliances, imperialism, and nationalism.) Austria-Hungary declared war on Serbia, as the shooting had acted like a trigger, each country now releasing their pent-up tension toward their rival. The Austro-Hungarians were then driven out of Bosnia.
Could it have been prevented?
As nearly every assassin set to kill Ferdinand had failed. it was simply a fluke that the sixth managed to gun him down. A whole series of event had to go particularly correct in order for the opportunity to line up - if any one thing had changed, Franz Ferdinand would likely not have died that day.
Even if Ferdinand's assassination were prevented, there's still no guarantee it could have stopped WWI. There were many other factors, and tensions were high among nations and ethnic groups the way it was. Unfortunately, we'll never know.