I experienced the same error when configuring the WP-Mail-SMTP
plugin in Wordpress.
The problem would persist even when I have 'triple checked' the settings and login credentials, and am able to log in manually using a browser.
There's a list of steps you can take to fix this.
Display Unlock Captcha
page to give your app or website permission to sign in to Gmail. Click Continue
or follow the instructions.