No access error

I have 2 different security groups, each has a manager and a team of employees. I set up the security groups and roles as mentioned in https://docs.suitecrm.com/user/security-suite-groups/#_a_typical_hierarchy_setup.

When an employee creates an account and assigns it to another employee in the same group (which he should not be able to do), he gets an error saying you do not have access to this area. Contact the site administrator to obtain access. But the account still gets created and assigned to the other employee.

How do i prevent this from happening?

If no one should be allowed to assign an account to someone else, then the easiest would be to remove Assigned user from the edit view.
Managers would also not be able to reassign an account, but they still could do that with Mass Update.

Or, better, if you are familiar with SuiteCRM framework, extend custom/modules/Accounts/views/view.edit.php to check role of current user and disable or hide the Assigned user field depending on the role.