Captain Marvel was created by Fawcett Comics over a year and a half after Superman was created by DC Comics. The character did so well that he was outselling Superman in the 40's.
DC Comics filed suit against Fawcett, claiming that Captain Marvel was a rip-off of Superman. DC prevailed in court in 1953, and Fawcett was forced to retire Captain Marvel permanently.
In the late 60's, Marvel Comics acquired the rights to the name "Captain Marvel," and created a superhero that was completely different from both the original Captain Marvel and Superman. Thus, they couldn't be sued by DC.
In 1972, as comic books were surging in popularity, DC was looking for new properties to publish and licensed the Captain Marvel characters from Fawcett. But when they tried to publish the comic book as "The Original Captain Marvel," Marvel Comics sent DC a cease-and-desist letter. Thus DC had to retitle the comic book, "Shazam!"
In order to retain their trademark, Marvel must publish a Captain Marvel title at least once every two years.