The town was Amu to its Arab visitors, and the Portuguese later called it Lamon and gave the name to the whole island. It is believed to have been founded in 1370, which makes it the oldest continually inhabited town in Kenya and one of the first Swahili settlements on the coast. An Arab traveller wrote of it in 1441, after meeting a judge from Lamu in Mecca.
Portugal arrived in 1506. A ship blockaded the town, the rest of the fleet followed, and the king agreed to an annual tribute plus 600 Meticals on the spot. Portugal wanted a monopoly on shipping along the coast and taxed exports on trade routes that already existed. Lamu pushed back in the 1580s, rising against the Portuguese, and in 1652 Oman helped it resist them.
From the late 17th century to the early 19th, Lamu was an Omani protectorate, and these years mark its golden age. The town ran as a republic under the Yumbe, a council of elders who sat in a palace that is now an empty ruined plot. Poets, craftsmen and traders thrived, and many of the town's buildings date from these years. Women writers held a higher status here than elsewhere in Kenya at the time. In 1858 Mwana Kupona composed her long poem Utendi Mwana Kupona here.
In 1812 an army from Pate and the Mazrui landed at Shela to take Lamu. Locals fought them on the beach and drove them off as they tried to flee in their boats. Afraid of another attack, Lamu asked Oman for a Busaidi garrison, which was stationed in the new fort on the seafront.
By the middle of the 19th century Lamu answered to the sultan of Zanzibar. Germany claimed the neighbouring Wituland in 1885 and saw Lamu as a useful base, opening a post office in 1888 that is said to have been the first on the East African coast. Britain took control in 1890 under the Heligoland-Zanzibar Treaty. The British ran the fort as a prison, and a governor's residence became today's Lamu Museum.
The old economy rested on the slave trade, which ended in 1907. Ivory, mangrove, turtle shells and rhinoceros horn also left by sea for the Middle East and India. Abolition hurt, and so did the Uganda Railroad of 1901, which began at Mombasa, a rival port. Tourism has helped since the early 2000s, and Lamu is popular with backpackers.
Kenya became independent in 1963, but the central government has had little influence here, and Lamu keeps some local autonomy. Trouble has come from outside. Al Shabaab kidnappings put Lamu off limits in September 2011, and the US lifted its travel restriction on 4 April 2012. Two attacks nearby in July 2014 killed 29 people. A port at Manda Bay, part of the LAPSSET project, was started in 2009. In 2010 the Global Heritage Fund named Lamu among 12 sites worldwide most at risk of irreparable damage.