WARNING: This page is about a different car, the 2016 Subaru Outback and 2016 Subaru Legacy. However, it is still accessible from the selected car via links, so may be relevant.
Make sure that the engine ground terminal has no contamination, corrosion or looseness and is properly connected to the engine.
Fig 1: Locating Engine Ground Terminal And Engine Assembly Bolt