A report into safety failures that forced 17 Edinburgh schools to close has highlighted a lack of proper scrutiny of the construction work.
The independent report has criticised the council and the partnership which managed the building contracts, as well as the construction company.
City of Edinburgh Council said lessons would be learned from the report.
Nine tonnes of masonry fell at Oxgangs Primary School in January 2016 during a storm.
Ten primaries, five secondaries and two additional support needs schools were shut because of concerns over the standard of construction in the city.
About 7,600 pupils were affected by the closures.
City of Edinburgh Council asked John Cole, an experienced architect from Northern Ireland, to investigate the closure of the 17 Edinburgh schools built under the PPP1 project.
In his report, he said: "The fact that no injuries or fatalities to children resulted from the collapse of the gable wall at Oxgangs School was a matter of timing and luck.
"Approximately nine tonnes of masonry fell on an area where children could easily have been standing or passing through.
"One does not require much imagination to think of what the consequences might have been if it had happened an hour or so later."
The 250-page report identified fundamental defects which led to the wall collapse:
- not enough wall ties
- the wrong type of ties were used
- wall cavities were not uniform.
The report said: "It is the view of the inquiry that the primary cause of the collapse of the wall at Oxgangs school was poor quality construction in the building of the wall, which failed to achieve the required minimum embedment of 50mm for the wall ties, particularly in the outer leaf of the cavity wall. The poor quality relates to all three of the following aspects:
- the direct laying of the bricks and the positioning of the wall ties
- the direct supervision of the laying of the bricks and the positioning of the wall ties
- the quality assurance processes used by the sub-contractor and main contractor to confirm the quality of the construction of the walls
"All three issues were ultimately the responsibility of the design and build contractor in charge of the site."
The report said it was not the result of an isolated case of a rogue bricklayer.
It said the substandard brick-laying was either not inspected or was ignored, that an appropriate level of independent scrutiny was missing; and that having a clerk of works may have made a difference.
Mr Cole also questions whether the drive for faster, lower-cost construction is to the detriment of quality and safety.
The report said the fundamental weakness was the lack of proper scrutiny of building work by the council and Edinburgh Schools Partnership, which managed the PPP contract.
The report also said: "There was an over-reliance on the part of the council, without adequate evidence, that others in the project structure, including those building the schools would comprehensively fulfil this essential role."
The report also concluded that the finance model was not responsible for defective construction.
Mr Cole also highlighted a failure to properly store and maintain the relevant documents.
He said closing the schools had been the only practical and safe course of action, and that finding alternative arrangements for more than 7,600 pupils was a "remarkable feat". The impact on the children's education had been "relatively limited".
His report was originally expected by the end of 2016, but was delayed by several weeks after Mr Cole was advised that any organisation or individual criticised in the investigation must be given time to respond.
The schools affected by the closures were all built or refurbished as part of the same public private partnership scheme.
They were built by Miller Construction, which was acquired by Galliford Try in 2014.
City of Edinburgh Council said it was drawing up an action plan to ensure confidence in the safety of all its buildings.
An Edinburgh Schools Partnership spokesman said: "We have fully cooperated with the council and Professor Cole in trying to establish the facts of what happened with the schools affected.
"Having only just received a copy of the report, we will now take time to consider its findings in detail before commenting further."
Andrew Kerr, City of Edinburgh Council's chief executive, said: "The report pulls no punches and makes clear what went wrong, the reasons for it and where responsibility lay.
"Clearly there are lessons for the council and I will now be drawing up an action plan to take our recommendations forward to ensure everyone can have confidence in the safety of all of our buildings.
"The council, our public and private sector partners both in Scotland and across the United Kingdom, need to take on board the issues raised and address the concerns highlighted in the report as they have far-reaching implications for the construction industry."
Kevin Stewart, Minister for Housing and Local Government, said: "The safety of people in public buildings is an absolute priority and I am very concerned by some of the findings highlighted in this report."
Larry Flanagan, EIS General Secretary, said: "This report issues a stark warning - to Edinburgh, to local authorities and to all those responsible for the construction and maintenance of our schools - that they must take action to ensure that all buildings are well-designed, properly-built and maintained to an extremely high standard.
"This is not an area where corners or costs should ever be cut.
"The legacy of the PPP/PFI funding model is too many inferior buildings, for which we will all be paying a vastly inflated price for decades to come. Scotland's pupils and school staff and, indeed, Scottish taxpayers deserve far better."