The animal, which measured four metres 40 centimetres, was found in shallow water at Filey Bay on Thursday evening.
A member of the public reported it around 6pm to the charity British Divers Marine Live Rescue, initially believing the shark, which was still alive, to be a whale.
A team of specialist volunteers were sent to the beach, where a crowd was already gathered trying to help the basking shark. The Coastguard and RNLI were also assisting.
The rescuers managed to guide the shark back into the water as the tide came in, but it appeated to be struggling and was listing to its right side and circling in the shallows.
As sharks are fish, they obtain oxygen from the water via their gills, and there were fears it could have suffered brain damage due to oxygen deprivation while on the beach.
The shark continued to remain near the beach and became stranded again. Later in the evening, the decision was made by a vet to humanely euthanise it. The male was a juvenile on the verge of maturity.
A post-mortem will now be performed to establish how it died.
Basking sharks are the second-largest type of shark, but are one of the few vegetarian species, feeding only on plankton, and are harmless to humans. They can grow up to eight metres in length.
British Divers Marine Life Rescue said:- "Basking sharks are generally a seasonal visitor to the UK, mostly being seen from spring until autumn, however there have been occasional sightings in winter too. Satellite tagging studies in the UK show that they can move across the Atlantic to places as far afield as North America and Africa. They are most often encountered along the west coast of the UK, with sightings in the North Sea and eastern English Channel being somewhat rare.
"They are the second largest fish in the ocean after the whale shark and can reach lengths of over 10 metres. They feed only on plankton by filter feeding - swimming along with their mouth open and using specialised ‘rakers’ in the gills to extract their food as it passes through them. They do have teeth, but as they have evolved to no longer need them they have virtually disappeared and measure only a few millimetres long. They are thought to live for over 50 years.
"Basking sharks are listed as endangered by the International Union for the Conservation of Nature's Red List and are protected from harm and disturbance in the UK. They are very vulnerable to disturbance from water users and people are advised to keep their distance, to not approach, follow or touch them and to avoid groups. If the shark decides to come closer to you then allow it to interact on its terms and leave again.
"Thank you to all medics, Filey lifeboat station, Filey Coastguard, Scarborough Sea Life Sanctuary and RSPCA who attended, plus our hotline co-ordinator Teri, who did what they could for the animal under these unusual and difficult circumstances."