(Adds details on battle, context)

SIRTE, Libya, Oct 20 (Reuters) - Libyan pro-government forces have freed five foreign nationals held by Islamic State in Sirte after heavy fighting in their battle to capture the final district of the city, a local official said on Thursday.

Islamic State took over Sirte more than a year ago, profiting from chaos caused by infighting among rival brigades of Libyan forces who once battled together to oust Muammar Gaddafi in 2011, but steadily turned against each other.

Two of the freed foreigners were from Turkey, two from India and one from Bangladesh, said Rida Issa, a spokesman for the Bonyan Marsous forces which have been battling for six months against militants in Sirte.

"There was a desperate resistance by Daesh, but it was confronted by heavy weapons," Issa said, using one of the Arabic names for Islamic State.

Forces from the western city of Misrata, allied with the U.N.-backed government in Tripoli, have been leading the battle to oust Islamic State from Sirte, helped since August by U.S. air strikes and small teams of Western special forces.

But they have been facing fierce resistance from snipers, car bombs and booby-traps as Islamic State fighters dig in for house-to-house fighting in the last residential districts held by the militant group.

On Thursday, pro-government forces killed at least 20 Islamic State fighters as they pushed into the 600 District of Sirte, one of the last held by militants who control an area now less than one square kilometer, local officials said.

After facing heavy casualties at the start of the campaign, Misrata forces have increasingly turned to the use of tanks and armed vehicles to clear a path for ground troops.

No details were given about how or where the five foreigners where captured, but Islamic State has attacked oilfields and kidnapped foreign workers over the last two years.

In May 2015, the group kidnapped a Czech, an Austrian and a Bangladeshi among other foreigners when they overran an oilfield in the south of Sirte. In February last year, they beheaded a group of Egyptian Christians captured in Libya.

Losing Sirte would deprive Islamic State of its major base outside its Iraq and Syria territory just as a U.S.-backed alliance helps Iraqi forces recapture the city of Mosul, the largest city the militants control there.

But the U.N.-backed government in Tripoli is struggling to expand its influence and faces opposition from hardliners on all sides of Libya's political divide. A victory in Sirte for Misrata forces is already pressuring military rivals in the east who oppose the Tripoli government.

(Reporting by Ismail Zitouni in Sirte,; Ahmed Elumami in Tripoli; Writing by Patrick Markey; Editing by Louise Ireland and Andew Hay) ((pat.markey@thomsonreuters.com; +213-661-692993; Reuters Messaging: pat.markey.thomsonreuters.com@reuters.net))