The Maine started out as an armored cruiser, commissioned in 1895 in response to the Brazilian battleship Riachuelo and general Latin American naval buildups in the 1890s. She managed the exceptionally neat trick of being outdated before she was done, mostly because people started using armored cruisers as quick trade enforcers rather than mini-battleships during her three-year construction time. But hey, it's not like they were building a man o' war.
In 1898, Cuba was in the last months of its war for independence from Spain, helped considerably by Spain's simultaneous struggle to keep control of the Philippines. The Maine trundled on down to Havana from Key West, to make sure that all the plantations American companies bought didn't get mysteriously set on fire, and on the night of February 15, exploded, killing most of the crew.
The general reaction was that Spain had done it with a bomb or mine, despite the lack of evidence for any conclusion at all (hard to get forensics teams into a war zone). The New York Journal and World, owned by William Randolph Hearst and Joseph Pulitzer respectively, pushed that idea for all they were worth, being unconstrained by little things like 'facts' and 'not setting their pants on fire'. There were already plenty of hawks urging war with Spain (and ideally US possession of Cuba) and in April, the McKinley administration did, indeed, declare war, though the Maine wasn't named in the resolution Congress passed.
So was Spain responsible? Frankly, we still don't know, and it's likely we never will, but the evidence we do have makes it sound awfully improbable. The 1898 investigation, conducted by Spain, pointed out that none of the characteristics of a mine detonation were present. An aquatic explosion would have caused a column of water and plenty of dead fish in the area, neither of which were there. Havana was calm that night, so subsurface waves couldn't have pushed the mine into the Maine, and neither could wind; that left electrical detonation, but there weren't any cables either. Lastly, mines didn't usually blow up munitions compartments, but the Maine's were wrecked.
The American investigation said it was a mine, but the whole thing was designed to come to that conclusion. For starters, the board was filled with junior officers -- hard to tell a superior officer he screwed up. Secondly, there was only one guy giving testimony on explosions, and he basically just said "Nope" when they asked him if a fire in the fuel stores could have blown up the ammo dumps. Last, the records from the investigation don't actually draw logical lines from the testimony of the divers who went down to look at the wreck and the committee's claim that it was totally a mine, you guys.
There's been more investigation since then, and a couple of things came to light. One, when the Maine was being built, the Navy switched from anthracite coal, which didn't make much smoke, to bituminous, which burned hotter (letting the ship go faster), but also let off gases, and two guesses what happens to the fumes from coal. Multiple fires were reported on ships using bituminous coal from that time.
So while we don't really know, smart bet's on the coal catching fire, spreading to the gunpowder, and the whole thing going to hell in a handbasket from there.