Graeme Carlyle and John Tait were on a trip off Dunbar when they spotted the basking shark. The fish are frequently seen off the west coast, but it is rarer to see them in the North Sea near land.
The friends, from Musselburgh, East Lothian, first noticed a 3ft fin sticking out of the water.
Mr Carlyle, a taxi driver, said: “I thought it was a killer whale at first, because there were some around here last year.
“This was a couple of hundred metres away, so we manoeuvred the boat towards it, and as we approached we cut the engine to reduce the noise and disturbance. At that point the shark just came straight towards us and basically brushed up against the side of the 16ft boat.”
Basking sharks are the second largest fish. They are filter feeders, so are harmless to humans.