Thirty-one defendants, including senior military officers, were each given four life sentences at the trial in the southwestern city of Mugla, the private Dogan news agency reported.
They include former brigadier general Gokhan Sahin Sonmezates who was accused of directing the plot. Former elite commando Zekeriya Kuzu, who was famously found hiding in a cave four days after the failed coup, also received a life term.
A further nine defendants each received a single life sentence, Dogan added.
Another key figure in the trial, Erdogan's former military aide-de-camp Ali Yazici, was sentenced to 18 years in jail. Just one suspect out of 47 in total, former lieutenant colonel Huseyin Yilmaz, was acquitted.
The trial began on February 20 and is one of many such processes taking place across Turkey to try those who allegedly took part in the failed bid to oust Erdogan on July 15, 2016.
Some verdicts have already been handed out in lower-profile cases but it is the first ruling involving alleged top plotters.
The failed coup left 249 people dead, not including the putschists, and the authorities have vowed no compromise will be made in bringing those involved to justice.
Two police officers were killed by the so-called "assassination team" while guarding the hotel.
Guzel Eker, the mother of one of the officers Nedip Cengiz Eker, described her relief and pain at the verdict.
"I am burning inside. It is enough for me that they have been given life sentences," she said, quoted by state-run Anadolu news agency.
Over 50,000 people have been arrested under the state of emergency imposed following the coup bid during a heavily criticised crackdown which has raised fears over Turkey's justice system in the West.
Turkey accuses Pennsylvania-based Muslim cleric Fethullah Gulen of orchestrating the attempted coup. Gulen, a former Erdogan ally turned arch-foe, strongly denies Ankara's claims.
Gulen was also on trial in absentia in Mugla. But the judge separated his case from the trial along with two other suspects.
Ravza Kavakci Kan, ruling Justice and Development Party deputy leader, praised the judicial process after hearing the verdict in court.
"This gives us hope that the courts are delivering verdicts after this ugly, treacherous coup attempt," she said, quoted by Anadolu.
One of the lawyers representing the prime ministry, Halit Cokan, said the verdict stemmed from an "open trial" and demonstrated "Turkey was a state with the rule of law".
'15 minutes from death'
Erdogan has said the assassination plot left him minutes from death after he fled the Grand Yazici Hotel in Marmaris, where he had been holidaying with his family, and went back to Istanbul by plane.
"If I had stayed 10 or 15 additional minutes there, I would have been killed or I would have been taken," Erdogan told CNN in an interview just days after the coup.
But some commentators have cast doubt on whether the president was in such immediate danger as the "assassination team" only arrived at the hotel well after he had left.
According to the parliamentary commission that investigated the coup plot, a 34-man team of putschists arrived at Erdogan's hotel at 3.20 am (0020 GMT). But Erdogan landed in Istanbul at 3.40 am (0040 GMT).
Some Erdogan supporters had called for the plotters to face the death penalty, which Turkey abolished in 2004 as part of its bid to join the European Union.
At least 200 people outside the court waving Turkish flags shouted "we want the death penalty" and "we want justice", as they called for Gulen to be extradited to Turkey to be tried.
(Except for the headline, this story has not been edited by NDTV staff and is published from a syndicated feed.)