This literally means 'to complete, finish' but can (and usually does) involve a regret over having done something. Also it can be used sarcastically to mean the speaker really wanted to do something, but gives a halfhearted apology. For example, 最後のクーキーを食べてしまった。 I unfortunately ate the last cookie. Of course there really wasn't anything unfortunate about it.
The construction is usually after the ~te form of any verb
全部のお金を使ってしまいました。
zenbu no okane o tsukatte shimaimashita.
Unfortunately, I spent all my money.私は完全に日本語を忘れてしまった。
watashi wa kanzen ni nihongo o wasurete shimatta.
Unfortunately, I have completely forgotten Japanese.
Another very useful variation is ~chatta. This is informal and is used by both male and female speakers. chau is made by combining te shimau -> chau
試験に落ちちゃった。
shiken ni ochichatta.
I flunked the test unfortunately.
or in the present tense
ケーキを全部食べちゃう。
ke-