Is it legal to leave the scene of an accident?

No. If you witnessed the accident you are supposed to give a statement to law enforcement prior to leaving.