Who wrote the Qur'an?
This question has two parts: who the Qur'an says its author is, and who wrote it down. The first can be answered from the text, quoted below. The second is history, and we keep it separate.
Short answer
The Qur'an says it is the word of God (Allah), "sent down" in Arabic through a messenger spirit to Muhammad, and that Muhammad did not compose it. It records that his opponents said otherwise, and it answers them.
It says little about how it was written down. It says the Prophet did not write any scripture before it, and it calls itself a book on written pages.
What the Qur'an claims about its source
From its second surah, the Qur'an calls itself a book without doubt and attributes itself to the Lord of the worlds:
ذَٰلِكَ ٱلْكِتَٰبُ لَا رَيْبَ ۛ فِيهِ ۛ هُدًۭى لِّلْمُتَّقِينَ
This is the Book about which there is no doubt, a guidance for those conscious of Allah -
وَمَا كَانَ هَٰذَا ٱلْقُرْءَانُ أَن يُفْتَرَىٰ مِن دُونِ ٱللَّهِ وَلَٰكِن تَصْدِيقَ ٱلَّذِى بَيْنَ يَدَيْهِ وَتَفْصِيلَ ٱلْكِتَٰبِ لَا رَيْبَ فِيهِ مِن رَّبِّ ٱلْعَٰلَمِينَ
And it was not [possible] for this Qur'an to be produced by other than Allah, but [it is] a confirmation of what was before it and a detailed explanation of the [former] Scripture, about which there is no doubt, from the Lord of the worlds.
It denies that the Prophet invented any of it, and states the consequence if he had:
إِنَّهُۥ لَقَوْلُ رَسُولٍۢ كَرِيمٍۢ
[That] indeed, the Qur'an is the word of a noble Messenger.
وَمَا هُوَ بِقَوْلِ شَاعِرٍۢ ۚ قَلِيلًۭا مَّا تُؤْمِنُونَ
And it is not the word of a poet; little do you believe.
وَلَا بِقَوْلِ كَاهِنٍۢ ۚ قَلِيلًۭا مَّا تَذَكَّرُونَ
Nor the word of a soothsayer; little do you remember.
تَنزِيلٌۭ مِّن رَّبِّ ٱلْعَٰلَمِينَ
[It is] a revelation from the Lord of the worlds.
وَلَوْ تَقَوَّلَ عَلَيْنَا بَعْضَ ٱلْأَقَاوِيلِ
And if Muhammad had made up about Us some [false] sayings,
لَأَخَذْنَا مِنْهُ بِٱلْيَمِينِ
We would have seized him by the right hand;
ثُمَّ لَقَطَعْنَا مِنْهُ ٱلْوَتِينَ
Then We would have cut from him the aorta.
فَمَا مِنكُم مِّنْ أَحَدٍ عَنْهُ حَٰجِزِينَ
And there is no one of you who could prevent [Us] from him.
How it says it arrived
It names the means: a trustworthy spirit, to the heart of the Prophet, in clear Arabic.
وَإِنَّهُۥ لَتَنزِيلُ رَبِّ ٱلْعَٰلَمِينَ
And indeed, the Qur'an is the revelation of the Lord of the worlds.
نَزَلَ بِهِ ٱلرُّوحُ ٱلْأَمِينُ
The Trustworthy Spirit has brought it down
عَلَىٰ قَلْبِكَ لِتَكُونَ مِنَ ٱلْمُنذِرِينَ
Upon your heart, [O Muhammad] - that you may be of the warners -
بِلِسَانٍ عَرَبِىٍّۢ مُّبِينٍۢ
In a clear Arabic language.
إِنَّآ أَنزَلْنَٰهُ قُرْءَٰنًا عَرَبِيًّۭا لَّعَلَّكُمْ تَعْقِلُونَ
Indeed, We have sent it down as an Arabic Qur'an that you might understand.
It also says it came in parts, over time, and that this was deliberate:
وَقُرْءَانًۭا فَرَقْنَٰهُ لِتَقْرَأَهُۥ عَلَى ٱلنَّاسِ عَلَىٰ مُكْثٍۢ وَنَزَّلْنَٰهُ تَنزِيلًۭا
And [it is] a Qur'an which We have separated [by intervals] that you might recite it to the people over a prolonged period. And We have sent it down progressively.
وَقَالَ ٱلَّذِينَ كَفَرُوا۟ لَوْلَا نُزِّلَ عَلَيْهِ ٱلْقُرْءَانُ جُمْلَةًۭ وَٰحِدَةًۭ ۚ كَذَٰلِكَ لِنُثَبِّتَ بِهِۦ فُؤَادَكَ ۖ وَرَتَّلْنَٰهُ تَرْتِيلًۭا
And those who disbelieve say, "Why was the Qur'an not revealed to him all at once?" Thus [it is] that We may strengthen thereby your heart. And We have spaced it distinctly.
The objections it records
The Qur'an quotes its critics. They said a human taught him, that he copied old stories written down for him, or that he was a poet:
وَلَقَدْ نَعْلَمُ أَنَّهُمْ يَقُولُونَ إِنَّمَا يُعَلِّمُهُۥ بَشَرٌۭ ۗ لِّسَانُ ٱلَّذِى يُلْحِدُونَ إِلَيْهِ أَعْجَمِىٌّۭ وَهَٰذَا لِسَانٌ عَرَبِىٌّۭ مُّبِينٌ
And We certainly know that they say, "It is only a human being who teaches the Prophet." The tongue of the one they refer to is foreign, and this Qur'an is [in] a clear Arabic language.
وَقَالَ ٱلَّذِينَ كَفَرُوٓا۟ إِنْ هَٰذَآ إِلَّآ إِفْكٌ ٱفْتَرَىٰهُ وَأَعَانَهُۥ عَلَيْهِ قَوْمٌ ءَاخَرُونَ ۖ فَقَدْ جَآءُو ظُلْمًۭا وَزُورًۭا
And those who disbelieve say, "This [Qur'an] is not except a falsehood he invented, and another people assisted him in it." But they have committed an injustice and a lie.
وَقَالُوٓا۟ أَسَٰطِيرُ ٱلْأَوَّلِينَ ٱكْتَتَبَهَا فَهِىَ تُمْلَىٰ عَلَيْهِ بُكْرَةًۭ وَأَصِيلًۭا
And they say, "Legends of the former peoples which he has written down, and they are dictated to him morning and afternoon."
قُلْ أَنزَلَهُ ٱلَّذِى يَعْلَمُ ٱلسِّرَّ فِى ٱلسَّمَٰوَٰتِ وَٱلْأَرْضِ ۚ إِنَّهُۥ كَانَ غَفُورًۭا رَّحِيمًۭا
Say, [O Muhammad], "It has been revealed by He who knows [every] secret within the heavens and the earth. Indeed, He is ever Forgiving and Merciful."
أَمْ يَقُولُونَ تَقَوَّلَهُۥ ۚ بَل لَّا يُؤْمِنُونَ
Or do they say, "He has made it up"? Rather, they do not believe.
فَلْيَأْتُوا۟ بِحَدِيثٍۢ مِّثْلِهِۦٓ إِن كَانُوا۟ صَٰدِقِينَ
Then let them produce a statement like it, if they should be truthful.
The tests it proposes
It invites its readers to test the claim: bring something like it, and look for internal contradiction.
وَإِن كُنتُمْ فِى رَيْبٍۢ مِّمَّا نَزَّلْنَا عَلَىٰ عَبْدِنَا فَأْتُوا۟ بِسُورَةٍۢ مِّن مِّثْلِهِۦ وَٱدْعُوا۟ شُهَدَآءَكُم مِّن دُونِ ٱللَّهِ إِن كُنتُمْ صَٰدِقِينَ
And if you are in doubt about what We have sent down upon Our Servant [Muhammad], then produce a surah the like thereof and call upon your witnesses other than Allah, if you should be truthful.
أَمْ يَقُولُونَ ٱفْتَرَىٰهُ ۖ قُلْ فَأْتُوا۟ بِسُورَةٍۢ مِّثْلِهِۦ وَٱدْعُوا۟ مَنِ ٱسْتَطَعْتُم مِّن دُونِ ٱللَّهِ إِن كُنتُمْ صَٰدِقِينَ
Or do they say [about the Prophet], "He invented it?" Say, "Then bring forth a surah like it and call upon [for assistance] whomever you can besides Allah, if you should be truthful."
قُل لَّئِنِ ٱجْتَمَعَتِ ٱلْإِنسُ وَٱلْجِنُّ عَلَىٰٓ أَن يَأْتُوا۟ بِمِثْلِ هَٰذَا ٱلْقُرْءَانِ لَا يَأْتُونَ بِمِثْلِهِۦ وَلَوْ كَانَ بَعْضُهُمْ لِبَعْضٍۢ ظَهِيرًۭا
Say, "If mankind and the jinn gathered in order to produce the like of this Qur'an, they could not produce the like of it, even if they were to each other assistants."
أَفَلَا يَتَدَبَّرُونَ ٱلْقُرْءَانَ ۚ وَلَوْ كَانَ مِنْ عِندِ غَيْرِ ٱللَّهِ لَوَجَدُوا۟ فِيهِ ٱخْتِلَٰفًۭا كَثِيرًۭا
Then do they not reflect upon the Qur'an? If it had been from [any] other than Allah, they would have found within it much contradiction.
What it says about writing
Surah Al-Alaq opens with a command to read, or recite, and soon mentions the pen:
ٱقْرَأْ بِٱسْمِ رَبِّكَ ٱلَّذِى خَلَقَ
Recite in the name of your Lord who created -
ٱلَّذِى عَلَّمَ بِٱلْقَلَمِ
Who taught by the pen -
It says the Prophet had not recited or written any scripture before it:
وَمَا كُنتَ تَتْلُوا۟ مِن قَبْلِهِۦ مِن كِتَٰبٍۢ وَلَا تَخُطُّهُۥ بِيَمِينِكَ ۖ إِذًۭا لَّٱرْتَابَ ٱلْمُبْطِلُونَ
And you did not recite before it any scripture, nor did you inscribe one with your right hand. Otherwise the falsifiers would have had [cause for] doubt.
And it describes itself as held on honoured, written pages:
فِى صُحُفٍۢ مُّكَرَّمَةٍۢ
[It is recorded] in honored sheets,
مَّرْفُوعَةٍۢ مُّطَهَّرَةٍۭ
Exalted and purified,
بِأَيْدِى سَفَرَةٍۢ
[Carried] by the hands of messenger-angels,
كِرَامٍۭ بَرَرَةٍۢ
Noble and dutiful.
It also promises its own preservation:
إِنَّا نَحْنُ نَزَّلْنَا ٱلذِّكْرَ وَإِنَّا لَهُۥ لَحَٰفِظُونَ
Indeed, it is We who sent down the Qur'an and indeed, We will be its guardian.