Daniel Johnston, a singer-songwriter and outsider artist who battled mental-health issues while recording hundreds of humorous, bittersweet songs that made him a near-mythical figure in indie rock, died Sept. 11 at his home in Waller, Tex., a farming town outside Houston. He was 58.

His brother and manager, Dick, said Mr. Johnston had been in a hospital with kidney problems and was released a day before his death “feeling good and everything,” when he apparently suffered a heart attack overnight.

Mr. Johnston had manic depression and schizophrenia and faced increasing health problems in recent years, notably diabetes and hydrocephalus, a buildup of fluid in the brain. Although he said he hoped to continue performing, he embarked in 2017 on what was billed as his “final tour,” joined by a backing band that included members of Wilco, Fugazi and Built to Spill — a roster of indie rock all-stars that spoke to his reputation as a master lyricist and intimate, uninhibited singer.

With a high-pitched voice and mild lisp, Mr. Johnston bared his soul in folksy songs about unrequited love, existential dread, his affection for the Beatles and the thrills of a speeding motorcycle. Emerging on Austin’s underground music scene in the mid-1980s, he used a $59 Sanyo boombox to record himself on acoustic guitar, organ and piano, and released cassette tapes decorated with his own ink and marker artwork.

In “Grievances,” the first song from his self-released debut, “Songs of Pain” (1981), he introduced the character of a young woman named Laurie, who rejected his advances and married an undertaker. “I saw you at the funeral,” Mr. Johnston sang. “You were standing there like a temple. I said ‘Hi, how are you, hello,’ and I pulled up a casket and crawled in.”

His music was unabashedly simple and straightforward — “the amazing thing is half these songs are the same three chords,” Built to Spill musician Doug Martsch once said — but drew a cult following, notably after Kurt Cobain of Nirvana was photographed in a T-shirt bearing the cover of Mr. Johnston’s album “Hi, How Are You” (1983).

“These songs are recorded so intimately, it almost feels like an invasion to listen to them,” wrote music critic Sasha Geffen, in a Pitchfork list that ranked “Hi, How Are You” the 145th best record of the 1980s. “He sang these earnest, infectious melodies to himself, into a cheap cassette recorder,” she added, “but he knew exactly how to reach people across time — to make them feel that, for the duration of a three-minute pop song, they weren’t on their own in this world.”

Mr. Johnston was covered by Tom Waits, Beck and Lana Del Rey, collaborated with singer Jad Fair of Half Japanese and guitarist Paul Leary of the Butthole Surfers, and was the subject of a 2005 documentary, “The Devil and Daniel Johnston,” that earned filmmaker Jeff Feuerzeig a directing award at the Sundance Film Festival.

He also found some success as an artist, inking cartoonlike drawings of an “alien frog” with eyes like lollipops, a boxer with a hollow head like an empty bowl, and Casper the Friendly Ghost. More than a dozen of his pictures were exhibited at the 2006 Whitney Biennial in Manhattan, after he had previously used his drawings to barter for comic books in Austin, or simply given them away.

But Mr. Johnston never quite achieved the mainstream success that he said he wanted — only one of his approximately 20 full-length albums, “Fun” (1994), was released by a major label — and seemed at times to have a loose grasp on what fame he did receive. When asked whether he was planning to travel from Texas to New York for the Whitney show, he told a New York Times reporter he was “not in any condition to go overseas.”

For many years, he was in and out of mental institutions and psychiatric wards, and lived with his elderly parents in Waller, working out of a garage filled with horror-movie posters, VHS tapes and comic books. He refused to sign with Elektra Records because he believed its band Metallica was trying to harm him, and addressed his mental-health issues in songs such as “Peek a Boo,” singing: “Junior high I lost my mind; I don’t know why, it’s a terrible thing. Since that day it’s been a struggle, trying to make sense out of scrambled eggs.”

Friends insisted he was no idiot savant, and Mr. Johnston himself expressed frustration at those who viewed his career solely in terms of mental illness. “Daniel knows exactly what he’s doing, and in a way he’s consciously exploited his mental illness,” Feuerzeig told Britain’s Telegraph newspaper in 2005. “You look at his notebooks and there’s all these pictures of Van Gogh. You listen to his songs and it’s like he’s diagnosing himself out of the DSM4 psychology manual.”

The youngest of five children, Daniel Dale Johnston was born into a Christian fundamentalist family in Sacramento on Jan. 22, 1961. His mother worked on airplanes during World War II before becoming a homemaker, and his father was a fighter pilot turned engineer, who occasionally flew his children on a private plane.

During one such flight, in 1990, Mr. Johnston “was in a psychotic state, took the keys out of the ignition and threw them out of the window,” his brother recalled by phone. “Dad was able to get the plane down and they survived.”

The family moved to New Cumberland, W.Va., when Daniel was young, and frequently gathered around the piano to sing church music. Daniel soon began banging out songs of his own, composing what he later described as “horror-movie themes” before singing more ambitious material while mowing the lawn as a teenager.

He recorded songs in the cellar and, after graduating high school, attended occasional art classes across the Ohio River, at Kent State University at East Liverpool. He moved to Houston in 1983, worked as a ride operator at the AstroWorld amusement park, sold corn dogs in a traveling carnival and eventually settled in Austin, taking a job at McDonald’s before launching his music career.

“I never thought I’d make it with the music that much,” he told the Times. “I thought I was going to be famous as a cartoonist.”

In addition to his brother, survivors include three sisters.

While Mr. Johnston’s songs “True Love Will Find You in the End” and “Some Things Last a Long Time” have become much-covered staples of indie rock, he said he was still trying to write a breakout song. “Hopefully, I could have a big hit someday, a real hit,” he told the Times in 2017. “I can’t stop writing. If I did stop, there could be nothing. Maybe everything would stop. So I won’t stop. I’ve got to keep it going.”