After Congress of Berlin Bosnia and Herzegovina was occupied by Austro-Hungary, but still was formally part of Ottoman Empire. As Montenegro and Serbia wanted to incorporate that Ottoman province together, they were dissapointed with that decision and as only consolation they got international recognition and Niš was annexed to Serbia.
Regardless to situation in Bosnia and Herzegovina Serbia found ally in Austro-Hungaria as they wanted to expand their territory to Eastern Balkan. In Serbo - Bulgarian war, Austro-Hungary saved Serbian independence when Austro - Hungarian representative Count Khevenhüller-Metsch threatened Bulgaria with Austro - Hungarian inclusion in war.
Situation changed in 1903. when Alexander Obrenović was killed by secret military organization Bela Ruka (White Hand). On throne came Karađorđević dynasty with Petar Karađorđević as new king. Goals of Serbia have changed and they found new ally in Russia and France. Cooling of relations with Austo-Hungary led to Pig war between Serbia and Austro-Hungary and annexation of Bosnia and Herezgovina almost led to real war.
In same time in Austro-Hungary strengthened idea of making unique Yugoslavic province in Austro-Hungary. However, emperor Franz Joseph I. refused conduction of this idea. Young Archduke Franz Ferdinand had different views and he actually wanted to rearrange Austro-Hungary in trialist monarchy. That idea wasn't very popular in Hungary because they would lost Rijeka and other territories (Austro-Hungarian Compromise), Riječka krpica. That idea also wasn't popular in Serbia and strongly yugoslavic- oriented people in Austro-Hungary (there was batch of them in that time).
Gavrilo Princip was one of them. He was member of Mlada Bosna which was controlled by Crna Ruka, terrorist organization which took part in many murders and criminal activities. He finally killed Archduke Franz Ferdinand and when Austro-Hungary request for conduction of investigation was refused, Austro-Hungary attacked Serbia starting chain reaction and beginning of WW1.
So assassination was trigger to World War I, and causes of WW1 were lying in Congress of Berlin, Bosnian Crisis and many other events in world not including only Austro-Hungary and Serbia, but other great world powers.
And yes, I recommend you to read @choster comment if you don't know difference between causes and trigger of the war.