Birth of magnetar seen for the first time