A blooper reel exists for this segment which shows what was going on behind the scenes.
According to IMDB, it was performed by Ivan Ditmars:
In the third season blooper reel, there is a shot of the M-4 on its dolly mount, being wheeled toward William Shatner by its operator. There is also a clip of Leonard Nimoy rocking his head sarcastically while "fill-in" elevator music plays during the scene where Spock plays Brahm's waltz for Kirk and Rayna. Ivan Ditmars' performance was dubbed in later.
From the same page, we have information that it was actually a composition or arrangement by Ivan Ditmars.
The Brahms paraphrase that Spock plays was written especially for this episode by Ivan Ditmars.
I briefly looked for a copy of the blooper reel, but I was not able to find it quickly.