Konta, who left the court in tears after being verbally abused by Romania captain Ilie Nastase in a Fed Cup tie last week, won 7-6 (7-5) 3-6 6-1.
The British number one found it tough but Osaka's challenge faded in set three as she struggled with an injury.
Konta will face Latvia's Anastasija Sevastova in round two.
The 25-year-old told BT Sport: "I think obviously you could tell she [Osaka] was struggling, I hope everything is OK with her and she recovers quickly.
"It was just important for me to stay on my own game. Even though I lost the second set I didn't feel like I did much wrong."
Konta had not dropped a set in two previous meetings with 19-year-old Osaka but clay is her weakest surface.
The world number seven struggled for consistency in the opening two sets but the key moment came when she saved two break points in the third game of the third set before then breaking Osaka's serve in the next.
Andy Murray is through to the third round of the Barcelona Open after Australia's Bernard Tomic withdrew before the match with an injured back.
Murray, 29, will play the winner between Spanish pair Albert Montanes and Feliciano Lopez in the last 16.
The world number one accepted a late wildcard for Barcelona after his third-round defeat by Spaniard Albert Ramos-Vinolas in Monte Carlo on Thursday.
Fellow Briton Dan Evans faces Austria's Dominic Thiem in the third round.
Both Evans and Murray will play their matches on Thursday.
Elsewhere, Britain's Aljaz Bedene beat the Netherlands' world number 46 Robin Haase 6-4 6-4 in the second round of the Hungarian Open in Budapest.
It was the 14th win in a row for Bedene, ranked 68th in the world, who will play either Ivo Karlovic or Damir Dzumhur in the next round.
Johanna Konta put a difficult week behind her to reach the second round of the Porsche Grand Prix in Stuttgart with victory over Japan's Naomi Osaka.