The Minke whale, believed to be up to 4 metres long, was first seen at Richmond Lock Bridge, south-west London, late on Sunday.
Images taken by residents showed the mammal had become stuck on the lock’s boat rollers.
Members from Britain's Royal National Lifeboat Institution (RNLI), British Divers Marine Life Rescue service and firefighters were called to aid the whale.
A seven-hour rescue attempt concluded at 1 am (local time) on Monday, with the whale swimming off.
Towards the ocean
It was spotted in the river in Teddington, 4 kilometres south of Richmond, according to locals, on Monday morning and has since turned around to swim back towards the ocean.
A spokesperson for the RNLI said: “Chiswick’s RNLI crew were tasked by London Coastguard at 8pm on Sunday 9 May and worked with the fire rescue service, police and British Divers Marine Life Rescue to try to free the whale.
“Together they managed to free it and were taking it to a deeper part of the river when it swam away.
“The whale was displaying concerning behaviours and experts in attendance were concerned that it may be unwell.”