The purpose of our existence as human beings is to serve our Lord and Creator in a manner which pleases Him. God (Allah) says in the Qur'an, "I did not create jinn and mankind except that they should worship Me." (Quran 51:56). Worship or service is understood as submission to God by sticking to His Commandments while doing so in the manner He prescribed and is pleased with.
This worship is the exclusive right of God, due to His bringing us into existence and providing our sustenance. God says in the Qur'an, "O mankind! Worship your Lord, Who created you and those who were before you so that you may become pious. Who has made the earth a resting place for you, and the sky as a canopy, and send down water (rain) from the sky and brought forth therewith fruits as a provision for you. Then do not set up rivals unto God(in worship) while you know (that He Alone has the right to be worshiped)." (Quran 2:21-22)
We as human beings are not here without any purpose, obligation or accountability. On the contrary, our lives have value and we will be held accountable to how we lived them in fulfillment of the purpose of our existence. God says in the Qur'an, "Did you think that We had created you in play (without any purpose), and that you would not be brought back to Us?" (Quran 23:115).
As for why God did all this, He says in the Qur'an, "And your Lord creates whatever He wills and chooses." (Quran 28:68) and "And God does whatever He wills." (Quran 14:27).