According to CIA history, President Truman was responsible for the creation of the CIA, and according to the NYT, it was because of the unforseen attacks of Pearl Harbor.
The Starfleet charter states:
Article 14, Section 31 of the Charter made allowances for bending Starfleet regulations in times of extraordinary threat.
Right below that sentence on the wiki page it says:
This section was cited as the foundation for Section 31 even into the late 24th century.
So we have the why, but who created Section 31? Was there a specific individual or was it a committee?