* Three people killed, including gunman - police

* Police say gunfire inside cafe prompted them to move in

* Gunman had history of mental instability and extremism -PM

* Some hostages forced to make videos with gunman's demands

* Suspicious package found in government building inCanberra (Adds Foreign Affairs department evacuated in Canberra,paragraphs 7-8)

By Lincoln Feast and Colin Packham

SYDNEY, Dec 16 (Reuters) - Heavily armed Australian policestormed a Sydney cafe early on Tuesday morning and freedterrified hostages held there at gunpoint, in a dramatic end toa 16-hour siege in which two captives and the attacker werekilled.

Authorities have not publicly identified the gunman, but apolice source named him as Man Haron Monis, an Iranian refugeeand self-styled sheikh known for sending hate mail to thefamilies of Australian troops killed in Afghanistan. He wascharged last year with being an accessory to the murder of hisex-wife but had been free on bail.

During the siege, several videos were posted on social mediaapparently showing hostages inside the Lindt cafe in Sydney'scentral business district making demands on behalf of Monis.

The gunman, whom hostages referred to as "brother", demandedto talk to Prime Minister Tony Abbott, the delivery of anIslamic State flag, and that media broadcast that Australia wasunder attack by Islamic State.

Abbott said the gunman was well known to authorities and hada history of extremism and mental instability.

Police are investigating whether the two hostages werekilled by the gunman or died in the crossfire, said AndrewScipione, police commissioner for the state of New South Wales.

With Australia on edge after the siege, police said theDepartment of Foreign Affairs building in the capital, Canberra,had been evacuated on Tuesday after a suspicious package wasfound in the canteen.

Few other details were available, and there was no immediateindication of any possible link with events in Sydney.

Around 2 a.m. local time (1500 GMT on Monday), at least sixpeople believed to have been held captive in the Sydney cafemanaged to flee after gunshots were heard coming from inside.

Police then moved in, with heavy gunfire and blasts fromstun grenades echoing from the building.

"They made the call because they believed at that time ifthey didn't enter there would have been many more lives lost,"Scipione told reporters just before dawn.

CAFE MANAGER, LAWYER KILLED

Police said a 50-year-old man, believed to be the attacker,was killed. Television pictures showed he appeared to have beenarmed with a sawn-off shotgun.

A man aged 34 and a 38-year-old woman were also killed,police said. The man was the cafe manager, and the woman was amother and lawyer, Sydney media reported.

At least four were wounded, including a policeman hit in theface with shotgun pellets. Among the wounded was a 75-year-oldwoman who was shot in the shoulder, police said. Two otherpregnant women who were among the hostages were taken tohospital for assessment. All were in stable condition.

Medics tried to resuscitate at least one person after theraid, a Reuters witness said. Bomb squad members moved in tosearch for explosives, but none were found.

So far 17 hostages have been accounted for, including atleast five who were released or escaped on Monday.

The area around the cafe remained cordoned off with policetape on Tuesday morning.

Office workers stood in long queues outside florist shops,as hundreds of bouquets formed a makeshift shrine near the cafe,while flags flew at half mast across the country.

PM Abbott and his wife also laid wreaths at the site.

A memorial service, attended by community leaders includingGovernor-General Peter Cosgrove, was held at St Mary's Cathedralon Tuesday, barely a block from where the siege unfolded.

Leaders from around the world had expressed their concernover the siege, including Stephen Harper, the prime minister ofCanada, which suffered an attack on its parliament by asuspected jihadist sympathiser in October.

NO LINKS TO TERROR GROUPS

Monis was found guilty in 2012 of sending threateningletters to the families of eight Australian soldiers killed inAfghanistan as a protest against Australia's involvement there.He was also facing more than 40 sexual assault charges.

"He had a long history of violent crime, infatuation withextremism and mental instability," Abbott told reporters inCanberra. The prime minister did not identify the gunman.

New South Wales Premier Mike Baird declined to comment whenasked by a journalist whether it was appropriate for Monis to befree on bail.

A U.S. security official said the U.S. government was beingadvised by Australia that there was no sign at this stage thatthe gunman was connected to known terrorist organisations.

Although the hostage taker was known to the authorities,security experts said preventing attacks by people acting alonewas difficult.

"We are entering a new phase of terrorism that is far moredangerous and more difficult to defeat than al Qaeda ever was,"said Cornell University law professor Jens David Ohlin,speaking in New York.

Australia, a staunch ally of the United States and itsescalating action against Islamic State in Syria and Iraq, hasbeen on high alert for attacks by home-grown militants returningfrom fighting in the Middle East or their supporters.

News footage showed hostages in the cafe holding up a blackand white banner displaying the Shahada, a declaration of faithin Islam. The banner has been popular among Sunni Islamistmilitant groups such as Islamic State and al Qaeda.

In September, anti-terrorism police said they had thwartedan imminent threat to behead a random member of the public and, days later, a teenager in the city of Melbourne was shot deadafter attacking two anti-terrorism officers with a knife.

The siege cafe is in Martin Place, a pedestrian strip thatwas revealed as a potential location for the thwarted beheading.

Muslim leaders urged calm. The Australian National ImamsCouncil condemned "this criminal act unequivocally" in a jointstatement with the Grand Mufti of Australia.

A social media movement showing solidarity with AustralianMuslims was also gathering steam.

(Additional reporting by Jane Wardell, Matt Siegel, SwatiPandey, Wayne Cole and Jason Reed in Sydney and Mark Hosenballin Washington; Writing by Dean Yates and Paul Tait; Editing byWill Waterman; Editing by Will Waterman)