Brahms wrote the first two movements, along with an Adagio, in the summer of 1862 and added the finale in 1865. He then dropped the Adagio, so the sonata has no slow movement. It is dedicated to Josef Gänsbacher, a singing teacher and amateur cellist, and Simrock published it in 1866 after Breitkopf & Härtel turned it down.
The title names the piano first, as a sonata for piano and cello, and the piano is meant to be a full partner, never just an accompanist. The music looks back to Bach: the finale’s fugue subject comes from Contrapunctus 13 of The Art of Fugue. When Gänsbacher once complained that he could not hear his own cello, Brahms was not sympathetic.