Shares of Demand Media Inc. rose 4 percent in after-hours trading on Monday after the online content company moved from a profit to a loss in the third quarter on higher revenue and viewership.

After the markets closed the Santa Monica company reported net income of $3.2 million (4 cents a share), compared with a net loss of $4.1 million (5 cents) in the same period a year earlier. Revenue rose 20 percent to $98.1 million.

The company struggled last year after Google adjusted its search algorithm to favor high quality content. But Demand appears to have recovered, with its portfolio of websites surpassing 125 million monthly unique visitors during the quarter. Page views were up 33 percent, but revenue per thousand pages was down 11 percent.

“For the first time in over a year, we increased our content investments for two consecutive quarters as we expanded the distribution of our content platform,” Chief Executive Richard Rosenblatt said in a statement.

Demand raised its 2012 guidance to reflect its growth, estimating that revenue will fall between $379 million and $381 million for the year.

Shares earlier closed up 50 cents, or 6 percent, to $8.74 on the New York Stock Exchange.