The possibility of making an optional bequest (وصية) and distributing the remainder according to the prescribed shares is present in the Quran.
من بعد وصية يوصين بها
... after any bequest they [may have] made
— Quran 4:11-12
It is also within the Quran that restraint is place on the bequest so as not to deprive the legal heirs:
من بعد وصية يوصى بها أو دين غير مضار
... after any bequest which was made ... as long as there is no detriment [caused]
— Quran 4:12
The specifics (limiting to no more than a third) is not in the Quran but in hadith:
الثلث والثلث كثير
One-third, yet even one-third is too much
Note that various madhabs allow for making and enforcing a bequest of more than a third with the permission of the heirs.