LONDON — A 360-foot-long barge that was set loose by violent weather in the North Sea was secured on Thursday, after the oil companies BP and ConocoPhillips evacuated hundreds of workers from two oil platforms and temporarily halted production.

The barge drifted past one of the oil installations as it moved toward the Norwegian coast, said Borghild Eldoen, a spokeswoman for the Joint Rescue Coordination Center in Stavanger, Norway. “It was a dramatic situation for some hours,” she said.

Georg Eide, the chairman of Eide Marine Services, the Norwegian company that owns the barge, said the vessel had been brought under control and was being towed toward Norway.

The barge, which is used to transport cargo, was returning to Norway from Tunisia after the completion of a project carried out on behalf of the German Navy when the tow line broke in “extreme weather” in the North Sea on Wednesday afternoon, Mr. Eide said in an email.