At "The Volokh Conspiracy" Jonathan Adler asks whether there are any science fiction books that would qualify as literary masterpieces. As one commenter notes early on, a number of Jules Verne's novels are obvious cases of science fiction works that qualify as literary masterpieces. What I found interesting about the discussion, though, was that almost immediately the running favorite was Walter J. Miller, Jr.'s A Canticle for Leibowitz; because that was going to be my answer. It's exquisite, influential, and likely to last for a very long time. If you haven't read it, you should, particularly if you like science fiction.
I would also like to suggest that Olaf Stapledon's Sirius and Starmaker are both excellent attempts to craft literary masterpieces in science fiction format -- the former more successful than the latter -- even if you don't think they quite make it.