FYI: The scene you're thinking of takes place near the end, when Kirk confronts "God" on an alien planet . . . .
And, if you're interested, Kirk comes to a similar realization in "The Enemy Within," one of the original TV episodes. (Written by Richard Matheson.)