The enormous cetacean, which can grow up to 55 feet long, was spotted by tourists on a rib heading from Anstruther to NatureScot's Isle of May National Nature Reserve (NNR).
As the vessel approached the famous seabird island, the whale surfaced several times nearby, blowing from its blowhole.
Remarkably, it circled the boat at a distance of around 20 metres to give everyone on board a close up view.
The humpback, which remained in the area for around two hours on Monday, is thought to be the first spotted in the area this year.
David Steel, NatureScot's reserve manager on the Isle of May, said: "You never know what you might see on a trip to the Isle of May and oh boy did yesterday deliver for a select few visitors, in the form of a humpback whale.
"As one of the visitor boats was approaching the island a large humpback whale surfaced nearby and circled the boat before moving on.
"In recent years humpbacks have started over-wintering in the Firth of Forth although this was only the third record in the last eight years from the island."
He added: "The Isle of May seas are certainly worth watching and lets hope our special visitor returns for all to see."
The humpback whale population is said to be slowly recovering in the north-east Atlantic, and individuals have been spotted previously in the Firth of Forth. The latest visitor, thought to be an adult, may have been playing or following prey.
Danny Groves of Whale and Dolphin Conservation (WDC) said: "Humpback whales are massive, growing to 17 metres in length, and travel some of the furthest distances of any whale. They are found in all the world’s major oceans and seen on occasion around the British Isles, more commonly sighted off the west coasts of Ireland and Scotland.
"Individuals also occasionally turn up elsewhere, including Cornwall, but it must have been a real treat for those who were lucky enough to see this particular traveller.
"Most populations undertake huge annual migrations, moving between mating and calving grounds in warmer, tropical waters, and feeding grounds in colder, more bountiful waters.
"Unfortunately, humpback whales were hunted extensively in years gone by, and still are in some places. In some areas, like the north Atlantic, their numbers are thought to be recovering, yet in others, like the north west Pacific, there is still a major cause for concern."
Several types of cetaceans have been spotted in the Firth of Forth in recent years, including regular dolphin sightings. In November, however, a rare sei whale stranded on the shore at Dalgety Bay in Fife. Many of its bones and other samples were recovered by National Museums Scotland for research.
Whales, together with dolphins and porpoises, are protected by wildlife legislation including the Wildlife and Countryside Act 1981. Under the Act it is an offence to intentionally or recklessly disturb them.